I am trying to make my code responsive so I used flutter_screenutil package for this , but every time I make width = 16.w or height = 100.h or textSize = 20.sp i only get Exception has occurred. LateError (LateInitializationError: Field '_splitScreenMode@697084504' has not been initialized.) I can not find the exact problem

that's an example of using flutter_screenutil

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:notification_screen_app/app_colors.dart';
import 'package:notification_screen_app/custom_app_bar_arrow_button.dart';
import 'package:notification_screen_app/custom_search_text_field.dart';

class SearchScreen extends StatelessWidget {
  const SearchScreen({Key? key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: const Size(double.infinity, 200),
        child: Padding(
          padding: EdgeInsets.symmetric(vertical: 30.0, horizontal: 16.0.h),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              CustomAppBarArrowButton(
                onTap: () {
                  Navigator.pop(context);
                },
              ),
              const CustomSearchTextField(),
            ],
          ),
        ),
      ),
      body: const Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text('Recent Search'),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text("Result for \"Yoga\""),
              Text(
                "152 Results Found",
                style: TextStyle(color: Color(0xffEE9F2F)),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

I tried to use this solution in my main file :

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
    return ScreenUtilInit(
      designSize: Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: () =>
          MaterialApp(
            //... other code
            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,
              );
            },
            theme: ThemeData(
              textTheme: TextTheme(
                //To support the following, you need to use the first initialization method
                  button: TextStyle(fontSize: 45.sp)
              ),
            ),
          ),
    );
  }
}

but it got me too much errors

0

There are 0 best solutions below