flutterdart

All final variables must be initialized, but '' isn't. Try adding an initializer for the field.dartfinal_not_initialized_constructor


I just need to pass an attribute to a constructor AppTheme, but i received an error:

All final variables must be initialized, but '' isn't. Try adding an initializer for the field.dartfinal_not_initialized_constructor

the code is:

class AppTheme extends StatelessWidget {
  const AppTheme({required this.navigator}); // => Cursor error 
  final  Widget navigator,
  @override
  Widget build(BuildContext context) {
    throw UnimplementedError();
  }}

Solution

  • class AppTheme extends StatelessWidget {
      const AppTheme({required this.navigator}); 
      final  Widget navigator; // replace ,(comma) to ;(Semicolon)
      @override
      Widget build(BuildContext context) {
        throw UnimplementedError();
      }}