2024-05-09 09:46:23 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-05-09 23:13:43 +02:00
|
|
|
import 'package:cpd/widgets/addhabit_popup.dart';
|
2024-05-12 00:08:54 +02:00
|
|
|
import '../database/habit.dart';
|
|
|
|
import 'package:cpd/database/db.dart';
|
|
|
|
import '../database/todo_db.dart';
|
|
|
|
import '../widgets/todo_widget.dart';
|
2024-05-09 09:46:23 +02:00
|
|
|
|
2024-05-12 00:08:54 +02:00
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
final HabitDatabase database = HabitDatabase();
|
|
|
|
runApp(MyApp(database: database));
|
2024-05-09 09:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2024-05-12 00:08:54 +02:00
|
|
|
final HabitDatabase database;
|
|
|
|
const MyApp({super.key, required this.database});
|
2024-05-09 09:46:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2024-05-12 00:08:54 +02:00
|
|
|
title: 'homepage',
|
2024-05-09 09:46:23 +02:00
|
|
|
theme: ThemeData(
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
2024-05-12 00:08:54 +02:00
|
|
|
home: MyHomePage(database: database, title: 'homepage'),
|
2024-05-09 09:46:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
2024-05-12 00:08:54 +02:00
|
|
|
final HabitDatabase database;
|
2024-05-09 09:46:23 +02:00
|
|
|
final String title;
|
2024-05-12 17:56:36 +02:00
|
|
|
const MyHomePage({super.key, required this.title, required this.database});
|
2024-05-09 09:46:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2024-05-12 17:56:36 +02:00
|
|
|
Future<List<Habit>>? futureTodos;
|
2024-05-12 00:08:54 +02:00
|
|
|
final todoDB = TodoDB();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
fetchTodos();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fetchTodos() async {
|
|
|
|
List<Habit>? habits = await todoDB.fetchAll();
|
|
|
|
setState(() {
|
2024-05-12 17:56:36 +02:00
|
|
|
futureTodos = Future.value(habits);
|
2024-05-12 00:08:54 +02:00
|
|
|
});
|
|
|
|
}
|
2024-05-09 09:46:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
toolbarHeight: 180,
|
|
|
|
flexibleSpace: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
bottomLeft: Radius.circular(30),
|
|
|
|
bottomRight: Radius.circular(30),
|
|
|
|
),
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Image.asset(
|
|
|
|
'assets/appbar_background.png',
|
|
|
|
width: double.infinity,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
const Positioned(
|
|
|
|
top: 20,
|
|
|
|
left: 20,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'step by step, day by day',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontFamily: 'Arial',
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
Text(
|
|
|
|
'You have #habitCounter for today',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontFamily: 'Roboto',
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-05-12 00:08:54 +02:00
|
|
|
body: Padding(
|
2024-05-09 09:46:23 +02:00
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: Center(
|
2024-05-12 00:08:54 +02:00
|
|
|
child: Container(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.green[100],
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(25)),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
const Text(
|
|
|
|
'Keep going queen',
|
|
|
|
style: TextStyle(
|
2024-05-09 09:46:23 +02:00
|
|
|
fontSize: 16.0,
|
|
|
|
color: Colors.black,
|
2024-05-12 00:08:54 +02:00
|
|
|
fontFamily: 'Roboto',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8.0),
|
|
|
|
const ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(30)),
|
|
|
|
child: SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: LinearProgressIndicator(
|
2024-05-09 09:46:23 +02:00
|
|
|
minHeight: 10,
|
|
|
|
color: Colors.green,
|
|
|
|
backgroundColor: Colors.white24,
|
|
|
|
value: 0.3, // Hier kannst du den Fortschritt des Indikators anpassen
|
|
|
|
),
|
2024-05-12 00:08:54 +02:00
|
|
|
),
|
2024-05-09 09:46:23 +02:00
|
|
|
),
|
2024-05-12 00:08:54 +02:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 10),
|
|
|
|
child: Divider(thickness: 3),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder<List<Habit>>(
|
|
|
|
future: futureTodos,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
} else {
|
|
|
|
final todos = snapshot.data ?? [];
|
|
|
|
return todos.isEmpty ? const Center(
|
|
|
|
child: Text(
|
|
|
|
'No habits',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) : ListView.separated(
|
|
|
|
separatorBuilder: (context, index) => const SizedBox(height: 12),
|
|
|
|
itemCount: todos.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final habit = todos[index];
|
|
|
|
return ListTile(
|
|
|
|
title: Text(
|
|
|
|
habit.title,
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
subtitle: Text(habit.subtitle ?? ''),
|
|
|
|
trailing: IconButton(
|
|
|
|
onPressed: () async {
|
|
|
|
await todoDB.delete(habit.id ?? 0);
|
|
|
|
fetchTodos();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.delete, color: Colors.red),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => CreateTodoWidget(
|
|
|
|
todo: habit,
|
|
|
|
onSubmit: (title, subtitle) async {
|
|
|
|
await todoDB.update(id: habit.id, title: title);
|
|
|
|
fetchTodos();
|
|
|
|
if (!mounted) return;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-05-09 09:46:23 +02:00
|
|
|
),
|
|
|
|
),
|
2024-05-12 00:08:54 +02:00
|
|
|
),
|
2024-05-09 09:46:23 +02:00
|
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
foregroundColor: Colors.deepPurpleAccent,
|
2024-05-12 00:08:54 +02:00
|
|
|
child: const Icon(Icons.add),
|
2024-05-09 09:46:23 +02:00
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2024-05-12 00:08:54 +02:00
|
|
|
builder: (_) => AddHabitPopup(
|
|
|
|
onSubmit: (title, subtitle) async {
|
|
|
|
await todoDB.create(title: title, subtitle: subtitle);
|
|
|
|
if (!mounted) return;
|
|
|
|
fetchTodos();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
2024-05-09 09:46:23 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-05-12 00:08:54 +02:00
|
|
|
}
|