I started developing a project with Flutter, how can I solve this error?

37 Views Asked by At
class AppBaseViewModel extends BaseViewModel {
  ThemeMode theme = ThemeMode.dark;
  AppBaseViewModel baseModel = locator<AppBaseViewModel>(); // After writing this code, an error appears on the emulator screen.
  init() {}

  changeTheme() {
    if (theme == ThemeMode.dark) {
      theme = ThemeMode.light;
    } else {
      theme = ThemeMode.dark;
    }
    baseModel.notifyListeners(); // After writing this code, an error appears on the emulator screen.
  }
}
class HomeView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ViewModelBuilder<HomeViewModel>.reactive(
        viewModelBuilder: () => HomeViewModel(),
        onModelReady: (model) => model.init(),
        builder: (context, model, child) => Scaffold(
      appBar: AppBar(
        actions: [
          IconButton(
            onPressed: () {
              model.baseModel.changeTheme(); // After writing this code, an error appears on the emulator screen.
            },
            icon: model.baseModel.theme == ThemeMode.light ? Icon(Icons.dark_mode) : Icon(Icons.light_mode), // After writing this code, an error appears on the emulator screen.
          ),
        ],
      ),
      body: Container(
        child: Center(
          child: Text(
            "Hello from TikTok App",
            style: Theme.of(context).textTheme.headline6,
          ),
        ),
      ),
    ));
  }
}

I'm starting to get this error after I write the parts that I specified with the comment line. The code does not give an error, but the error seen in the picture appears in the emulator. Before adding the parts I specified in the code, my program is running. Could you help?(https://i.stack.imgur.com/KhHYr.png)

0

There are 0 best solutions below