Code Monkey home page Code Monkey logo

Comments (18)

mozomig avatar mozomig commented on August 22, 2024 10

I'm find solution for 5.9.0, it's happens because in release mode when starting app screen width and screen height in ScreenUtil instance was 0 and fontSizeResolver calculate scale font incorrect.

My solution:

final designSize = const Size(412, 892);

ScreenUtilInit(
          designSize: designSize,
          fontSizeResolver: (fontSize, instance) {
            final display = View.of(context).display;
            final screenSize = display.size / display.devicePixelRatio;
            final scaleWidth = screenSize.width / designSize.width;

            return fontSize * scaleWidth;
          },
          builder: (context, _) {
              return MaterialApp.....
})

from flutter_screenutil.

hmartiins avatar hmartiins commented on August 22, 2024 3

I'm find solution for 5.9.0, it's happens because in release mode when starting app screen width and screen height in ScreenUtil instance was 0 and fontSizeResolver calculate scale font incorrect.

My solution:

final designSize = const Size(412, 892);

ScreenUtilInit(
          designSize: designSize,
          fontSizeResolver: (fontSize, instance) {
            final display = View.of(context).display;
            final screenSize = display.size / display.devicePixelRatio;
            final scaleWidth = screenSize.width / designSize.width;

            return fontSize * scaleWidth;
          },
          builder: (context, _) {
              return MaterialApp.....
})

Work for me! Thanks!

from flutter_screenutil.

hamiranisahil avatar hamiranisahil commented on August 22, 2024 1

@Mounir-Bouaiche Sure, I'll adjust it with the necessary tweaks and push it to a new branch.

I'll also check the new alpha version with the ScreenUtilSingleton widget. I'll refer to the docs for the alpha version. Thanks!

from flutter_screenutil.

tamremariam avatar tamremariam commented on August 22, 2024 1

void main() async {
// Add this line
await ScreenUtil.ensureScreenSize(); // adding this line solved my problem
runApp(MyApp());
}
...

from flutter_screenutil.

bishal-rumba007 avatar bishal-rumba007 commented on August 22, 2024 1

@tamremariam I am not sure about that, You might also need to add :
MaterialApp( ... builder: (ctx, child) { ScreenUtil.init(ctx); return Theme( data: ThemeData( primarySwatch: Colors.blue, textTheme: TextTheme(bodyText2: TextStyle(fontSize: 30.sp)), ), child: HomePage(title: 'FlutterScreenUtil Demo'), ); }, )

even so, I recommend not using after having gone through many issues in production.
Flutter already has rich set of Widgets to handle responsiveness.

from flutter_screenutil.

sagnik-sanyal avatar sagnik-sanyal commented on August 22, 2024

I am also having this same issue, did you find a way to resolve this @Akshaykakkodi ?

from flutter_screenutil.

YuchenTOR avatar YuchenTOR commented on August 22, 2024

try use 5.8.4

from flutter_screenutil.

mozomig avatar mozomig commented on August 22, 2024

same problem

from flutter_screenutil.

spring321 avatar spring321 commented on August 22, 2024

我找到了 5.9.0 的解决方案,发生这种情况是因为在发布模式下启动应用程序时 ScreenUtil 实例中的屏幕宽度和屏幕高度为 0 并且 fontSizeResolver 计算比例字体不正确。

我的解决方案:

final designSize = const Size(412, 892);

ScreenUtilInit(
          designSize: designSize,
          fontSizeResolver: (fontSize, instance) {
            final display = View.of(context).display;
            final screenSize = display.size / display.devicePixelRatio;
            final scaleWidth = screenSize.width / designSize.width;

            return fontSize * scaleWidth;
          },
          builder: (context, _) {
              return MaterialApp.....
})

None of the above works for me

[✓] Flutter (Channel stable, 3.19.3, on macOS 14.3.1 23D60 darwin-arm64 (Rosetta), locale zh-Hans-CN)
• Flutter version 3.19.3 on channel stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ba39319843 (6 weeks ago),
• Engine revision 2e4ba9c6fb
• Dart version 3.3.1
• DevTools version 2.31.1
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn

In version 5.9.0, Android phones can run with the screen off and wiget will be missing

from flutter_screenutil.

Mounir-Bouaiche avatar Mounir-Bouaiche commented on August 22, 2024

@spring321 @hmartiins @mozomig @sagnik-sanyal @Akshaykakkodi Can you try latest version 5.9.2 and see, if problem persist, thanks. Also read #568

from flutter_screenutil.

sahilmind avatar sahilmind commented on August 22, 2024

Tested flutter_screenutil: ^5.9.3 on Pixel 6a and faced the same issue.

from flutter_screenutil.

Mounir-Bouaiche avatar Mounir-Bouaiche commented on August 22, 2024

@sahilmind I can't reproduce your problem. Can you provide a reproduction code ?

from flutter_screenutil.

hamiranisahil avatar hamiranisahil commented on August 22, 2024

@Mounir-Bouaiche I added the screenutil dependency and set the font size to 16.sp. The text is visible in debug mode but not in release mode on the Pixel 6a.

ScreenUtilInit(
      designSize: designSize,
      minTextAdapt: true,
      splitScreenMode: true,
      // Use builder only if you need to use library outside ScreenUtilInit context
      builder: (_, child) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          localizationsDelegates: AppLocalizations.localizationsDelegates,
          supportedLocales: AppLocalizations.supportedLocales,
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          home: const SplashPage(),
        );
      },
    );

I tried @mozomig's solution, and it works fine.

from flutter_screenutil.

Mounir-Bouaiche avatar Mounir-Bouaiche commented on August 22, 2024

@hamiranisahil I can't reproduce your problem.
I tried your code (flutter 3.13 + 3.19.5), and work good for me. Can you share a repo ?

screen-20240531-114022_1080x2400.mp4

from flutter_screenutil.

hamiranisahil avatar hamiranisahil commented on August 22, 2024

@Mounir-Bouaiche I can't share the repo now, but I'll create a demo to share. My Mac has Flutter 3.22.0 and Dart 3.4.0, and the app is a release APK.

from flutter_screenutil.

Mounir-Bouaiche avatar Mounir-Bouaiche commented on August 22, 2024

@Mounir-Bouaiche I can't share the repo now, but I'll create a demo to share. My Mac has Flutter 3.22.0 and Dart 3.4.0, and the app is a release APK.

@hamiranisahil You can use example from this repo by the way, adjust with your tweaks and push to a new branch. Thanks.
Also, could you check the new alpha version, it has a ScreenUtilSingleton widget, similar to ScreenUtilInit, if you're using only w/h/r/sp. See docs for alpha version

from flutter_screenutil.

bishal-rumba007 avatar bishal-rumba007 commented on August 22, 2024

I was facing the same issue when using 5.9.2 wih flutter 3.19.0 and above, here is stackoverflow link:
Stackoverflow Link

I had it working by following the documentation provided in pub.dev for hybrid development:
MaterialApp(
...
builder: (ctx, child) {
ScreenUtil.init(ctx);
return Theme(
data: lightTheme,
child: HomePage(title: 'FlutterScreenUtil Demo'),
);
},
)

It was working for me until I made changes in my project, and converted it to monorepo, the ThemeData theme() is imported from common package core, and now the issue persists again.
my folder structure looks like:

/super_app

  • apps

    • mini_app_1
    • mini_app_2
  • packages

    • core
      • lib
        • app_theme
  • melos.yaml

  • pubspec.yaml

from flutter_screenutil.

tamremariam avatar tamremariam commented on August 22, 2024

i had same issue my text all despaired after i close and open the release mode

from flutter_screenutil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.