OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.83k stars 485 forks source link

LateInitializationError: Field '_minTextAdapt@941084504' has not been initialized. #545

Closed mohamed-seiam closed 1 month ago

mohamed-seiam commented 5 months ago

i have this error suddenly when i run new application

Dhruvrajsinh7Span commented 5 months ago

I am having same issue did you find any solution

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

abdifitahseefle commented 4 months ago

I have same issue now this time while I am using this package for mobile dev responsive ui and I wondered why so far no one solved. waiting to be solve but dont know how long wiill that take

omar-khaium commented 3 months ago

Same issue

DAMHONGDUC commented 3 months ago

you guys have to wrap your MaterialApp with ScreenUtilInit, follow the docs:

void main() => runApp(MyApp());

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

  @override
  Widget build(BuildContext context) {
    //Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
    return ScreenUtilInit(
      designSize: const Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      // Use builder only if you need to use library outside ScreenUtilInit context
      builder: (_ , 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'),
    );
  }
}
Aditya7738 commented 3 months ago

I got solution. Here is my code, @override Widget build(BuildContext context) { return ScreenUtilInit( designSize: Size(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height), minTextAdapt: true, splitScreenMode: true, child: MaterialApp( title: Constants.app_name, builder: (context, child) { ScreenUtil.init(context); return Theme( child: Home(), data: ThemeData( textTheme: TextTheme( headline1: TextStyle( fontWeight: FontWeight.bold, fontSize: 11.sp, )), )); }, debugShowCheckedModeBanner: false, ), ); }

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

muhamedsaber commented 2 months ago

i got the same error

muhamedsaber commented 2 months ago

The MaterialApp should be returned From the ScreenUtilInit builder not as a child -- ScreenUtilInit( designSize: const Size(360, 690), minTextAdapt: true, splitScreenMode: true, builder: (_, child) { return MaterialApp( debugShowCheckedModeBanner: false, theme: isDarkMode ? darkThemeManager : lightThemeManager, onGenerateRoute: onGenerateRoute, ); });

michaelfeb commented 1 month ago

have same issue

Mounir-Bouaiche commented 1 month ago

You must use ScreenUtilInit widget on top of your widget. If they are on the same level, use builder.

Example when use child:

WidgetA(
  child: ScreenUtilInit(
    child: WidgetB(),
  ),
)

class WidgetB extends State..Widget {
  @override
  build(context) {
    return Text('', fontSize: 18.sp),
  }
}

Example when use builder:

WidgetA(
  child: ScreenUtilInit(
    builder: (_, __) {
      return Text('', fontSize: 18.sp);
    },
  ),
)

Example when use both:

WidgetA(
  child: ScreenUtilInit(
    builder: (_, child) {
      return Container(
        width: .2.sw,
        child: child,
      );
    },
    // Use child so WidgetB not get built every time .2.sw change
    child: WidgetB(),
  ),
)