Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font size gets zero in release mode. #130

Closed
sumitkakshapati opened this issue Jul 6, 2020 · 16 comments
Closed

font size gets zero in release mode. #130

sumitkakshapati opened this issue Jul 6, 2020 · 16 comments

Comments

@sumitkakshapati
Copy link

Flutter version : 1.17.5
Library version: 2.1.0
till version 1.1.0 where context was used it was working fine. after that i upgraded to version 2.1.0 than in debug mode it is working fine but when i build release apk all the font size turns into zero.

@lizhuoyuan
Copy link
Collaborator

2.1 I have tested it in the release test, and see if some necessary steps have not been performed.Because the version difference is too large, please take a look at the api

@Pilaba
Copy link

Pilaba commented Jul 8, 2020

Same issue, maybe is beacuse the use of MediaQueryData.fromWindow(window) instead of MediaQuery.of(context) in recent versions.

flutter/flutter#14113 (comment)

@lizhuoyuan
Copy link
Collaborator

lizhuoyuan commented Jul 8, 2020

Because the underlying code is the same, there should be no problem if the location of the call remains unchanged.But I will continue to test and see the possible problems
image

This is a newly created official demo. I used the latest version of the plug-in. There is no problem with flutter run --release.
My build apk is also normal.

Can you provide more?

@agent3bood
Copy link

agent3bood commented Jul 9, 2020

I had the same issue, the fix was to move my ScreenUti.init() from main() to inside the build()

Update: The above change did fix the issue in iPhone 6s+ but not iPhone 11.

void main() {
  Bloc.observer = LogBlocObserver();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Default design
    ScreenUtil.init(width: 414, height: 896, allowFontScaling: true);
    //
    return MultiBlocProvider(

@dufei816
Copy link

me too, in the first widget appBar not displayed,second widget no problem

@lizhuoyuan
Copy link
Collaborator

me too, in the first widget appBar not displayed,second widget no problem

Can you show the code?

@dufei816
Copy link

`void main() {
Catcher(
MyApp(),
debugConfig: Constants.debugOptions,
releaseConfig: Constants.releaseOptions,
);
if (Platform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle =
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}

class MyApp extends StatefulWidget {
@OverRide
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
submitPrivacyGrantResult() {
SharesdkPlugin.uploadPrivacyPermissionStatus(1, (bool success) {
if (success == true) {
} else {}
});
}

@OverRide
void initState() {
submitPrivacyGrantResult();
super.initState();
}

@OverRide
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: () {
LoginViewModel model = LoginViewModel();
model.initUser();
return model;
},
),
ChangeNotifierProvider(
create: (
) => ThemeViewModel(),
)
],
child: Consumer2<ThemeViewModel, LoginViewModel>(
builder: (context, model1, model2, __) {
return MaterialApp(
title: "LOXEN",
onGenerateRoute: (settings) => Routes.configRoutes(settings),
navigatorObservers: [routeObserver],
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('zh', 'ZH'),
const Locale('en', 'EN'),
],
theme: model1.themeData,
home: HomePageWidget(),
);
}));
}
}`

`class HomePageWidget extends StatelessWidget {

HomePageWidget({Key key}) : super(key: key) {
.....
}

@OverRide
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
ScreenUtil.init(context, width: 750, height: 1334);
return MultiProvider(
providers: [
.....
],
child: Scaffold(
body: Builder(
builder: (context) => Stack(
children: [
Offstage(
offstage: context.watch() != 0,
child: const InspirationListWidget(),
),
Offstage(
offstage: context.watch() != 1,
child: const MaterialIndexWidget(),
),
Offstage(
offstage: context.watch() != 2,
child: const StudyIndexWidget(),
),
Offstage(
offstage: context.watch() != 3,
child: const MasterIndexWidget(),
),
Offstage(
offstage: context.watch() != 4,
child: minePageWidget,
),
],
)),
bottomNavigationBar: Builder(
builder: (context) => BottomNavigationBar(
currentIndex: context.watch(),
onTap: (index) {
if (index == 3) {
if (context.read().isLogin()) {
Navigator.of(context).pushNamed(Routes.login_page);
return;
}
}
_bottomIndex.value = index;
},
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Image.asset(
'images/tab0_default.png',
width: 40.w,
height: 40.h,
),
activeIcon: Image.asset(
'images/tab0_active.png',
width: 40.w,
height: 40.h,
),
title: Text(StringResources.shou_ye,
style: TextStyle(
fontSize: 17.sp,
color: context.watch() != 0
? defaultColor
: activeColor))),
BottomNavigationBarItem(
icon: Image.asset(
'images/tab1_default.png',
width: 40.w,
height: 40.h,
),
activeIcon: Image.asset(
'images/tab1_active.png',
width: 40.w,
height: 40.h,
),
title: Text(StringResources.su_cai,
style: TextStyle(
fontSize: 17.sp,
color: context.watch() != 1
? defaultColor
: activeColor))),
BottomNavigationBarItem(
icon: Image.asset(
'images/tab2_default.png',
width: 40.w,
height: 40.h,
),
activeIcon: Image.asset(
'images/tab2_active.png',
width: 40.w,
height: 40.h,
),
title: Text(StringResources.xue_xi,
style: TextStyle(
fontSize: 17.sp,
color: context.watch() != 2
? defaultColor
: activeColor))),
BottomNavigationBarItem(
icon: Image.asset(
'images/tab3_default.png',
width: 40.w,
height: 40.h,
),
activeIcon: Image.asset(
'images/tab3_active.png',
width: 40.w,
height: 40.h,
),
title: Text(StringResources.da_shi_zhuo,
style: TextStyle(
fontSize: 17.sp,
color: context.watch() != 3
? defaultColor
: activeColor))),
BottomNavigationBarItem(
icon: Image.asset(
'images/tab4_default.png',
width: 40.w,
height: 40.h,
),
activeIcon: Image.asset(
'images/tab4_active.png',
width: 40.w,
height: 40.h,
),
title: Text(StringResources.wo_de,
style: TextStyle(
fontSize: 17.sp,
color: context.watch() != 4
? defaultColor
: activeColor)))
],
)),
),
);
}

void openSplash(BuildContext context) async {
var data = await SharedPreferencesUtil.getData(Constants.FIRST);
if (data == null) {
Navigator.push(context, MaterialPageRoute(builder: (_) => SplashPage()));
SharedPreferencesUtil.putData(Constants.FIRST, true);
}
}
}
`

BottomNavigationBarItem not displayed,appBar InspirationListWidget

`class InspirationListWidget extends StatelessWidget {
const InspirationListWidget({Key key}) : super(key: key);

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(80.h),
child: .......,
),
body:.........,
);
}
}
`

@sumitkakshapati
Copy link
Author

i also used it in main. and added it in the theme but it didn't work. i guess we have to use it after the material app in next widget like in 2nd widget after material app as before than only it works even if it don't required the context.

@lizhuoyuan
Copy link
Collaborator

i also used it in main. and added it in the theme but it didn't work. i guess we have to use it after the material app in next widget like in 2nd widget after material app as before than only it works even if it don't required the context.

Yes, although the context parameter is not needed, it actually needs to wait until dart obtains the screen data, generally this is when the context is obtained

@lizhuoyuan
Copy link
Collaborator

lizhuoyuan commented Jul 11, 2020

@dufei816
It looks ok, but I can't run it so I can't debug . So sad.
But I think it may be caused by the provider's update mechanism?

@An-uking
Copy link

@lizhuoyuan 我也是遇到了 测试机型 iphone 11 pro max . 手机上只有布局 没有文字 布局上的文字一个也显示不了

@An-uking
Copy link

An-uking commented Jul 13, 2020

@lizhuoyuan 加延时运行可以解决此问题
void main() {
Future.delayed(Duration(milliseconds: 100)).then((value){
runApp(MyApp());
});
}

@lizhuoyuan
Copy link
Collaborator

lizhuoyuan commented Jul 16, 2020

Hello everyone, I already have a plan to use ScreenUtil in MyApp.
And it should solve the problem that the screen parameters cannot be obtained.
After the test, I will organize the documents and submit the code.
A new version will be released this week.

sorry, This solution doesn’t work, damn flutter ,can not use ScreenUtil in MyApp.

@lizhuoyuan
Copy link
Collaborator

lizhuoyuan commented Jul 16, 2020

I resolved this at 2.3
And i will find a better way to improve it

@kenNg1
Copy link

kenNg1 commented Aug 11, 2022

@Timus23 did you do this? await ScreenUtil.ensureScreenSize();. See the documentation for hybrid method.

I had the same issue as you but after doing this, it was fixed in release mode.

@Abdulah-butt
Copy link

simply use
flutter_screenutil: 5.8.4

This version works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants