import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'db.dart';
import 'state/todo_state.dart';
import 'screens/home_screen.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await TodoDatabase.init();
  final todos = await TodoDatabase.loadTodos();

  final todoState = TodoState();
  todoState.setTodos(todos);

  runApp(
    ChangeNotifierProvider.value(
      value: todoState,
      child: MaterialApp(
        title: 'Dart Todo',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          colorSchemeSeed: Colors.deepPurple,
          useMaterial3: true,
          brightness: Brightness.light,
        ),
        home: const HomeScreen(),
      ),
    ),
  );
}
