OpenFlutter / flutter_screenutil

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

Font size difference in debug and release build #461

Closed StipT closed 1 year ago

StipT commented 1 year ago

Everything works and scales fine with debug build, but once I build the release version, font scaling doesn't work right. Has anyone come across this?

Device: Pixel 3a android-arm64 • Android 13 (API 33) (emulator)

app-debug.apk

image

app-release.apk

image

ScreenUtilInit

 @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: const Size(787, 375),
        builder: (BuildContext context, Widget? child) {
          return MaterialApp.router(
            localizationsDelegates: context.localizationDelegates,
            supportedLocales: context.supportedLocales,
            locale: context.locale,
            routerDelegate: _appRouter.delegate(),
            routeInformationParser: _appRouter.defaultRouteParser(),
            title: APP_NAME,
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              fontFamily: FontStyles.FONT_FAMILY,
              primaryColor: AppColors.vanDykeBrown,
              splashColor: AppColors.bistreBrown,
              colorScheme: ColorScheme.fromSwatch().copyWith(secondary: AppColors.gold),
              textSelectionTheme: const TextSelectionThemeData(
                cursorColor: AppColors.gold,
              ),
            ),
          );
        });
  }

Text styles used accross the app

class FontStyles {
  static const String FONT_FAMILY = "Belwe";

  // Regular Belwe

  static TextStyle regular15 = TextStyle(
    fontFamily: FONT_FAMILY,
    fontWeight: FontWeight.w400,
    fontSize: 15.sp,
    color: AppColors.white,
  );

  static TextStyle regular15Black = TextStyle(
    fontFamily: FONT_FAMILY,
    fontWeight: FontWeight.bold,
    fontSize: 15.sp,
    color: Colors.black,
  );

  static TextStyle regular17 = TextStyle(
    fontFamily: FONT_FAMILY,
    fontWeight: FontWeight.w400,
    fontSize: 17.sp,
    color: AppColors.white,
  );

...
}
lizhuoyuan commented 1 year ago

Do not use static This will be loaded before screenutil, at this time xx.sp is invalid