import 'package:flutter/material.dart';
import 'package:widgettest/services/theme.dart';
import 'package:widgettest/widgets/placeholder_widget.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget { 
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // This widget is the root of your application
  
  @override
  void initState(){
    super.initState();
    appTheme.addListener((){ //👈 this is to notify the app that the theme has changed
      setState(() {});       //👈 this is to force a rerender so that the changes are carried out
    })
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      themeMode: appTheme.themeMode, //👈 this is the themeMode defined in the AppTheme class
      darkTheme: darkTheme,          //👈 this is the darkTheme that we defined in the theme.dart file
      theme: lightTheme,             //👈 and this is the lightTheme
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return const Scaffold(
        appBar: AppBar(
          Title:'My App'
        ),
        body: PlaceholderWidget() // 👈 this is where your widget will be, whether it be the counter or otherwise
    );
  }
}