CPD_2024_todo/lib/main.dart

38 lines
958 B
Dart
Raw Normal View History

2024-10-22 20:42:08 +02:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:hive_flutter/hive_flutter.dart';
2024-10-22 20:42:08 +02:00
import 'providers/todo_provider.dart';
import 'screens/todo_list_screen.dart';
import 'storage/hive_todo_storage.dart';
import 'storage/todo_storage.dart';
2024-10-22 20:42:08 +02:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
await Hive.openBox('todoBox');
//choose preferred storage type here
final storage = HiveToDoStorage();
runApp(ToDoApp(storage: storage));
2024-10-22 20:42:08 +02:00
}
class ToDoApp extends StatelessWidget {
final ToDoStorage storage;
const ToDoApp({required this.storage});
2024-10-22 20:42:08 +02:00
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => ToDoProvider(storage),
2024-10-22 20:42:08 +02:00
child: MaterialApp(
title: 'To-Do List',
2024-10-22 20:42:08 +02:00
theme: ThemeData(
primarySwatch: Colors.green,
),
home: ToDoListScreen(),
),
);
}
}