Text is not showing in release mode
For getting adaptive text by depending on screen size, I used (.sp) in TextStyle in TextTheme. Using (.sp) inside text theme data , app works fine. But the issue occured when I tried to run it in release or profile mode. No text were showing in screen. Then i had to refine the textheme and remove all the (.sp).
From
static TextTheme lightTextTheme = TextTheme(
displayLarge: TextStyle(
fontSize: 30.sp,
fontWeight: FontWeight.w600,
color: AppColors.black,
),
displayMedium: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 25.sp,
color: AppColors.secondaryColor,
),
To
static TextTheme lightTextTheme = TextTheme(
displayLarge: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w600,
color: AppColors.black,
),
displayMedium: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 25,
color: AppColors.secondaryColor,
),
I have the same issue only happens in release mode and not for all Phones. I have run on 4 phones (2 android and 2 iphones) only one had the issue and only in release mode and not completely consistently there either. Sometimes when I started the app on the phone with the issue, it looked fine but then when I put it as into the background and brought it to foreground I had the issue.
Looks like the .sp value is returning zero for the text size.
this is my yaml entry flutter_screenutil: ^5.9.3 not sure the iOS version of the phone (its my partners phone) but can find out if need be.
I have the same issue only happens in release mode and not for all Phones. I have run on 4 phones (2 android and 2 iphones) only one had the issue and only in release mode and not completely consistently there either. Sometimes when I started the app on the phone with the issue, it looked fine but then when I put it as into the background and brought it to foreground I had the issue.
Looks like the .sp value is returning zero for the text size.
this is my yaml entry flutter_screenutil: ^5.9.3 not sure the iOS version of the phone (its my partners phone) but can find out if need be.
how did you fix that?
sorry didn't fix it, need to borrow the phone back and have another go. I centralized all my font sizes so only have one place to change from using .sp, I will focus back on it next week when I can get my hands on the phone.
here is my centralization code, class FontSizes { static double largeTitle36 = 36.sp; static double largeTitle32 = 32.sp; static double largeTitle30 = 30.sp; static double title24 = 24.sp; static double heading20 = 20.sp; static double body20 = 20.sp; static double caption12 = 12.sp; // static double largeTitle36 = 36; // static double largeTitle32 = 32; // static double largeTitle30 = 30; // static double title24 = 24; // static double heading20 = 20; // static double body20 = 20; // static double caption12 = 12; }
ok I might have found a solution, I have tested this on two phones that had issues and its working. But be interested if it works for you @ShafiMunshi.
Basically I put in a delay at the start using future builder, not sure why it works but 100mSecs seems to make all the difference, haven't done a binary search to find out how much time it really needs but 100mSec is acceptable solution.
class MyApp extends StatelessWidget { const MyApp({super.key});
Future
// This widget is the root of your application. @override Widget build(BuildContext context) { return FutureBuilder( future: initializeScreenUtil(context), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { // Show a loading indicator while waiting for initialization return const CircularProgressIndicator(); } else { return ScreenUtilInit( designSize: const Size(414, 892), // Set the design size of your app, used for scaling builder: (context, child) { return MaterialApp(
ok I might have found a solution, I have tested this on two phones that had issues and its working. But be interested if it works for you @ShafiMunshi.
Basically I put in a delay at the start using future builder, not sure why it works but 100mSecs seems to make all the difference, haven't done a binary search to find out how much time it really needs but 100mSec is acceptable solution.
class MyApp extends StatelessWidget { const MyApp({super.key});
Future initializeScreenUtil(BuildContext context) async { // Wait for a short duration to ensure initialization is complete await Future.delayed(const Duration(milliseconds: 100)); }
// This widget is the root of your application. @OverRide Widget build(BuildContext context) { return FutureBuilder( future: initializeScreenUtil(context), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { // Show a loading indicator while waiting for initialization return const CircularProgressIndicator(); } else { return ScreenUtilInit( designSize: const Size(414, 892), // Set the design size of your app, used for scaling builder: (context, child) { return MaterialApp(
Thanks for your help. Your code works truly flawless.
Ensure that the screen size is initialized before running the app.
// This is particularly useful for adapting UI layouts to different screen sizes.
await ScreenUtil.ensureScreenSize();
runApp(const MyApp());
Ensure that the screen size is initialized before running the app.
// This is particularly useful for adapting UI layouts to different screen sizes. await ScreenUtil.ensureScreenSize(); runApp(const MyApp());
This works. Thanks!