OpenFlutter / flutter_screenutil

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

App not rendering in real device on release mode or profile mode only debug mode working #341

Closed Ahsan161815 closed 2 years ago

Ahsan161815 commented 2 years ago

I have tried to solve this issue by changing emulators, Different plugin version, different flutter sdk version, following docs carefully but nothing helped.

lizhuoyuan commented 2 years ago

Show me your initialization code or more

Ahsan161815 commented 2 years ago

Thanks for taking time @lizhuoyuan Here is the main.dart file code

`import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:livescore/constants.dart';

void main() { runApp(SplashScreen()); }

class SplashScreen extends StatelessWidget { const SplashScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( home: ScreenUtilInit( designSize: const Size(375, 820), minTextAdapt: true, builder: () => const Home(), ) ); } }

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

@override Widget build(BuildContext context) { return Scaffold( backgroundColor: kOther2, body: Padding( padding: EdgeInsets.symmetric(horizontal: 40.w), child: Column( // mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 64.h,), Image.asset('assets/images/img.png', width: 291.w, height: 338.11.h,), SizedBox(height: 77.89.h,), Text('Discover all \nabout sport', style: TextStyle( fontSize: 40.sp, color: kWhite, fontFamily: 'SourceSansProS' ), ), SizedBox(height: 14.h,), Text('Search millions of jobs and get the \ninside scoop on companies. \nWWait for what? Let’s get start it!', style: TextStyle( fontSize: 16.sp, color: kGrey2, fontFamily: 'SourceSansProR' ), ), SizedBox(height: 45.h,), SizedBox( width: 199.w, child: ElevatedButton( onPressed: (){}, child: Text('Sign in', style: TextStyle( fontSize: 18.sp, fontFamily: 'SourceSansProS' ), ), style: ElevatedButton.styleFrom( primary: kBlue, padding: EdgeInsets.symmetric(horizontal: 60.w, vertical: 20.h), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16.r), ) ), ), ), SizedBox(height: 50.h,), ], ), ), ); } }`

Ahsan161815 commented 2 years ago

Flutter Doctor Output Here

[√] Flutter (Channel stable, 2.10.1, on Microsoft Windows [Version 10.0.18363.815], locale en-US) • Flutter version 2.10.1 at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision db747aa133 (9 days ago), 2022-02-09 13:57:35 -0600 • Engine revision ab46186b24 • Dart version 2.16.1 • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at C:\Users\Ahsan\AppData\Local\Android\sdk • Platform android-32, build-tools 32.1.0-rc1 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.0.32126.317 • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)

[√] IntelliJ IDEA Community Edition (version 2021.3) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart

[√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.18363.815] • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.102 • Edge (web) • edge • web-javascript • Microsoft Edge 98.0.1108.50

[√] HTTP Host Availability • All required HTTP hosts are available

[√] No issues found!

Ahsan161815 commented 2 years ago

Show me your initialization code or more

Debug Mode Screenshot_1645235529

Release Mode WhatsApp Image 2022-02-19 at 6 55 15 AM

lizhuoyuan commented 2 years ago

use ScreenUtil.setContext()

Ahsan161815 commented 2 years ago

use ScreenUtil.setContext()

Firstly I already Tried That I Copied all the code in flutter_screen_util First Example That didn't work.

After lots of trial and error I solved this issue

live3

When using class based widget Structure may it extends stateless or stateful Widget Android Studio intelisense Shouts to use const modifier when alowed to use const then that widget tree doesnt render at all in release app version if you remove it and let intelisense shout at you then it works fine.

It took me days to figure out.

I don't know if was my mistake, Android Studio or Flutter_Screen_utils.

fcaroca91 commented 2 years ago

Something similar happens to me, I worry that my widgets have constant constructors, but it is not possible to use the updates of the heights and widths when my web app resizes, will I have to avoid having constant constructors when using this package?

Ahsan161815 commented 2 years ago

Something similar happens to me, I worry that my widgets have constant constructors, but it is not possible to use the updates of the heights and widths when my web app resizes, will I have to avoid having constant constructors when using this package?

If it Works

lizhuoyuan commented 2 years ago

so should delete const.

KingsleyCheng commented 2 years ago

builder: (context, widget) { //add this line ScreenUtil.setContext(context); return MediaQuery( //Setting font does not change with system font size data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), child: widget!, ); },

BrunoJurkovic commented 2 years ago

Doesn't work for me, says there is no MediaQuery ancestor

builder: (context, widget) {

        //add this line

        ScreenUtil.setContext(context);

        return MediaQuery(

          //Setting font does not change with system font size

          data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),

          child: widget!,

        );

      },
BrunoJurkovic commented 2 years ago

You can check #350 for my solution for this problem.

abdulla-bey01 commented 2 years ago

use 5.0.2 version of package, i had use this version in my previous project, this version has no problem, i was fighting with error of non-seen texts in profile or release mode, you should change version in also pubspec.lock