简体   繁体   中英

Flutter: The argument type 'MultiProvider Function()' can't be assigned to the parameter type 'Widget Function(BuildContext)'

This flutter code throws The argument type 'MultiProvider Function()' can't be assigned to the parameter type 'Widget Function(BuildContext)'

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(460,790),
      builder: () => MultiProvider(
        providers: [
          ChangeNotifierProvider(create: (context) => api()),
          ChangeNotifierProvider(create: (context) => PageControllerProvider()),
          ChangeNotifierProvider(create: (context) => RequestProvider()),
          ChangeNotifierProvider(create: (context) => HistoryProvider()),
          ChangeNotifierProvider(create: (context) => ThemeProvider()),
        ],
        child: App()
      ),
    );
  }
}

Does anyone has an suggestion to fix this?

Thank you.

wrap you ScreenUtilInit with a Builder widget as shown in the code bellow .

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Builder(
       builder : () => ScreenUtilInit(
      designSize: Size(460,790),
      builder: () => MultiProvider(
        providers: [
          ChangeNotifierProvider(create: (context) => api()),
          ChangeNotifierProvider(create: (context) => PageControllerProvider()),
          ChangeNotifierProvider(create: (context) => RequestProvider()),
          ChangeNotifierProvider(create: (context) => HistoryProvider()),
          ChangeNotifierProvider(create: (context) => ThemeProvider()),
        ],
        child: App()
      ),
     )
    );
  }
}

Try updating the ScreenUtilInit package to the latest version. In the latest version (^5.5.3+2 at the time of writing), the signature of the builder parameter is changed to Function(BuildContext context, Widget? child)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM