import 'package:flutter/material.dart'; import 'addTimerDialog.dart'; import 'timer.dart'; class Countdown extends StatefulWidget { const Countdown({Key? key}) : super(key: key); @override State createState() => _CountdownState(); } class _CountdownState extends State { List timers = List.empty(growable: true); @override void initState() { super.initState(); timers.add(Timer(key: const Key("1"), target: DateTime.now().add(const Duration(seconds: 20)), label: "Countdown 1")); timers.add(Timer(key: const Key("2"), author: "goldbaja", target: DateTime.now().add(const Duration(days: 20)), label: "Sommerferien")); timers.add(Timer(key: const Key("3"), target: DateTime.now().add(const Duration(hours: 20)), label: "Joa")); timers.sort((a, b) => a.target.compareTo(b.target)); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Countdown"), actions: [ IconButton(onPressed: () { showDialog(context: context, builder: (context) => const AddTimerDialog()); }, icon: const Icon(Icons.add)), ], ), body: ReorderableListView( shrinkWrap: true, footer: Container( padding: const EdgeInsets.only(top: 30), child: Center( child: Text("Halte und Ziehe ein Element um es umzusortieren.", style: TextStyle(color: Theme.of(context).disabledColor)), ), ), onReorder: (int oldIndex, int newIndex) { }, children: timers, ), // body: ListView.separated( // itemBuilder: (context, index) => timers[index], // separatorBuilder: (context, index) => const Divider(), // itemCount: timers.length // ) ); } }