'ScreenUtilInit should be return but WillPopScope need to return at the same time
Update: I solved the first problem (merged codes). But now i have a different problem. I have LateError (LateInitializationError: Field '_instance@34075166' has not been initialized.)
for all of height: 380.h,
on this part need to delete .h
and .w
. When i deleted all of .h
and .w
codes running normally but application seems really awful. I understand what is the problem. These codes are not used:
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(640, 1340),
minTextAdapt: true,
splitScreenMode: true,
builder: () => MaterialApp(
theme: ThemeData(),
debugShowCheckedModeBanner: false,
supportedLocales: L10n.all,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
home: const SplashScreen(),
),
);
}
ScreenUtilInit
should be return because of height 50.h
or weight 30.w
.
This is the my all codes:
class ChoosePage extends StatefulWidget {
const ChoosePage({Key? key}) : super(key: key);
@override
_ChoosePageState createState() => _ChoosePageState();
}
@override
Widget build(BuildContext context) {
return StreamProvider<InternetConnectionStatus>(
initialData: InternetConnectionStatus.connected,
create: (_) {
return InternetConnectionChecker().onStatusChange;
},
child: MaterialApp(
title: 'Network Aware Application',
),);}
class _ChoosePageState extends State<ChoosePage> {
int _selectedIndex = 0;
late StreamSubscription subscription;
bool hasInternet = false;
ConnectivityResult result = ConnectivityResult.none;
late StreamSubscription internetSubscription;
@override
void initState() {
super.initState();
});
@override
void dispose() {
subscription.cancel();
internetSubscription.cancel();
super.dispose();
}
static final List<Widget> _widgetOptions = <Widget>[
const MainPage(),
const NearPage(),
const ExplorePage(),
const ProfilePage()
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _showExitDialog(context),
child: Scaffold(
backgroundColor: Colors.grey.shade100,
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
showUnselectedLabels: false,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(
Icons.home,
size: 60.h,
),
label: AppLocalizations.of(context)!.mainPage,
),
BottomNavigationBarItem(
icon: Icon(Icons.announcement, size: 60.h),
label: AppLocalizations.of(context)!.announcement,
),
BottomNavigationBarItem(
icon: Icon(Icons.explore, size: 60.h),
label: AppLocalizations.of(context)!.deliver,
),
BottomNavigationBarItem(
icon: Icon(Icons.person, size: 60.h),
label: AppLocalizations.of(context)!.profile,
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.blue,
onTap: _onItemTapped,
)),
);}}
Future<bool> _showExitDialog(BuildContext context) async {
return await showDialog(
context: context,
builder: (context) => _buildExitDialog(context),
);
}
AlertDialog _buildExitDialog(BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.onay),
content: Text(AppLocalizations.of(context)!.purge_detail),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(AppLocalizations.of(context)!.no),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(AppLocalizations.of(context)!.yes),
),
],
);
}
}
How can I get rid of this error? Because i can't delete all of .h and .w because of the contents of the page seems organized. Edit: I imported sizer package but how can i use it? Because when i use sizer package, i have same issue again. I can't delete
Widget build(BuildContext context) {
return StreamProvider(
and
Widget build(BuildContext context) {
return WillPopScope(
so have can i use sizer package?
ResponsiveSizer(
builder: (context, orientation, deviceType) {
return MaterialApp();
}
)
Solution 1:[1]
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(393, 830),//Design Size
minTextAdapt: true,
splitScreenMode: true,
builder: (_) => MaterialApp(
builder: (context, child) {
ScreenUtil.setContext(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!
);
},
title: 'My App',
home:HomePage(),
),
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DiyorbekDev |