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

Screenutil doesn't working on gridview builder #346

Closed mzsdev1 closed 2 years ago

mzsdev1 commented 2 years ago

Today I tested the app on a smaller phone. There was no error on the screen that I created as a listview. But it gave an error on the screen I created as gridview. The texts do not fit and the application does not work.

Bonus: I'm asking because I don't know. On the listview screen, 15 data is displayed on the large screen phone, while 9 data is displayed on the small screen phone. Is this normal?

sdk: ">=2.15.1 <3.0.0"

class MyApp extends StatelessWidget {
  const GetGames({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    return ScreenUtilInit(
      //minTextAdapt: true, => error
      splitScreenMode: true,
      designSize: const Size(360, 690),
      builder: () => GetMaterialApp(
        debugShowCheckedModeBanner: false,
        title: "My App Debug Mode",
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const HomeScreen(),
      ),
    );
  }
}

Also, when I try to write the following codes, it does not recognize and accept: (setContext) & (minTextAdapt: true,) and (child:widget)

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

Gridview builder screen:

final double itemHeight = 0.38.sh;  //266.h - 0.385.sh
final double itemWidth = 1.sw;

GridView.builder(
                shrinkWrap: true,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  childAspectRatio: itemWidth / itemHeight,
                  crossAxisCount: 1,
                ),
                scrollDirection: Axis.vertical,
                itemCount: getxDataController.data.length,
                itemBuilder: (BuildContext context, int index) {

                   return Padding(
                    padding: EdgeInsets.symmetric(
                      horizontal: 7.w,
                      vertical: 8.h,
                    ), etc...