OpenFlutter / flutter_screenutil

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

UI crashes in release mode #570

Closed bishal-rumba007 closed 1 week ago

bishal-rumba007 commented 3 weeks ago

I have been using flutter_screenutil for quite time now, but the latest updates in flutter version and the package version causes UI to crash in release mode. The Theme is not loading properly and all the UI gets lost and font is also not showing,

here is flutter doctor summary: Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.1, on Ubuntu 20.04.6 LTS 5.4.0-170-generic, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc2) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2023.2) [✓] VS Code (version 1.90.0) [✓] Connected device (3 available) [✓] Network resources

• No issues found!

how i am using: import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:job_portal_app/config/routes/app_route.dart'; import 'package:job_portal_app/l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:job_portal_app/shared/language/language_bloc/language_bloc.dart'; import 'package:leelaak_core/leelaak_core.dart';

class MainApp extends StatelessWidget { const MainApp({super.key});

@override Widget build(BuildContext context) { return BlocProvider( create: (context) { return LanguageBloc(); }, child: BlocBuilder<LanguageBloc, LanguageState>( builder: (context, state) { return MaterialApp.router( routerConfig: goRoute, debugShowCheckedModeBanner: false, builder: (context, child) { const designSize = Size(430, 932); ScreenUtil.init(context, designSize: designSize, minTextAdapt: true); return Theme( data: theme(), child: child!, ); }, ); }, ), ); } }

WhatsApp Image 2024-06-12 at 12 24 30 PM WhatsApp Image 2024-06-12 at 12 24 30 PM (1)

iamthejahid commented 3 weeks ago

Same here, not just only in production, in profile mode too!

bishal-rumba007 commented 1 week ago

@iamthejahid It seems I forgot to initialize the ScreenUtil instance in main method before hand accessing it in Material App. I followed their Hybrid way of using the package like so: 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'), ); }, )

But i forgot to add this: void main() async { // Add this line await ScreenUtil.ensureScreenSize(); runApp(MyApp()); }

in the main function.

However, I have made clear decision about never using this package anywhere and utilizing the flutters built in Widgets and MediaQuery in some places to make app responsive and adaptive at the same time. All this time, Flutter had rich set of Widgets to handle responsiveness. Hope this helps to any future viewers as well.

Note: Dont use this package!