Home > other >  error: The named parameter 'child' isn't defined
error: The named parameter 'child' isn't defined

Time:07-06

i try to change it in children but it doesn't change anything i've tried

  1. flutter clean
  2. pub get

but it show the same error


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

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

 @override
 Widget build(BuildContext context) {
   return ScreenUtilInit(
     designSize: Size(375,812),
     allowFontScaling: false,
     child: MaterialApp(
       debugShowCheckedModeBanner: false,
       title: "Presence",
       theme: ThemeData(
         scaffoldBackgroundColor: Constants.scaffoldBackgroundColor,
         visualDensity: VisualDensity.adaptivePlatformDensity,
         textTheme: GoogleFonts.poppinsTextTheme(),
       ),
       initialRoute: "/",
       onGenerateRoute: _onGenerateRoute,
     ),
   );
 }
}

CodePudding user response:

Try using a builder instead.

From the flutter_screenutil readme:

    return ScreenUtilInit(
      designSize: const Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context , child) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          title: 'First Method',
          // You can use the library anywhere in the app even in theme
          theme: ThemeData(
            primarySwatch: Colors.blue,
            textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
          ),
          home: child,
        );
      },
      child: const HomePage(title: 'First Method'),
    );

CodePudding user response:

In which widget are you trying to call child?

CodePudding user response:

You must need to declare home inside MaterialApp and give your initial page to that.

  • Related