skip to Main Content

I am working on a flutter application and using the screen util package ScreenUtil, but the app gives me an error when using the child attribute to insert the Material app widget. Here is my code:`

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:spoon_app/screens/splash_screen/mobile.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const Spoon());
}

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

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      minTextAdapt: true,
      splitScreenMode: true,

// when to use the child attribute it yields with an error

      child: MaterialApp(
        theme: ThemeData(
          scaffoldBackgroundColor: const Color(0XFFFFFFFF),
          textTheme: TextTheme(
            bodySmall: TextStyle(
                fontSize: 14.sp,
                fontFamily: "Alex",
                fontWeight: FontWeight.w400,
              height: 1.3.h,

            ),
            bodyMedium: TextStyle(
              fontSize: 12.sp,
              fontFamily: "Alex",
              fontWeight: FontWeight.w700,
            ),
              bodyLarge: const TextStyle(
                color: Colors.white,
                fontSize: 18,
                fontFamily: "Alex",
                fontWeight: FontWeight.w700,
              ),
              headlineMedium: const TextStyle(
                fontSize: 32,
                fontWeight: FontWeight.w500,
              ),
              headlineLarge: TextStyle(
            fontFamily: "Alex",
            fontSize: 32.sp,
            fontWeight: FontWeight.w500,
          )),
    ),
    debugShowCheckedModeBanner: false,
    title: "SpoonApp",
    home: MobileWelcomeScreen(),
  ),
    );
  }
}

`

in a speedy manner, am I in much need for a fix for my problem.

2

Answers


  1. Try to use builder and child attribute like this:

    @override
    Widget build(BuildContext context) {
      return ScreenUtilInit(
        designSize: const Size(375, 812),
        minTextAdapt: true,
        splitScreenMode: true,
        ensureScreenSize: true,
        builder: (_ , child) {
          return MaterialApp(
            theme: ThemeData(
              scaffoldBackgroundColor: const Color(0XFFFFFFFF),
              textTheme: TextTheme(
                  bodySmall: TextStyle(
                    fontSize: 14.sp,
                    fontFamily: "Alex",
                    fontWeight: FontWeight.w400,
                    height: 1.3.h,
                  ),
                  bodyMedium: TextStyle(
                    fontSize: 12.sp,
                    fontFamily: "Alex",
                    fontWeight: FontWeight.w700,
                  ),
                  bodyLarge: const TextStyle(
                    color: Colors.white,
                    fontSize: 18,
                    fontFamily: "Alex",
                    fontWeight: FontWeight.w700,
                  ),
                  headlineMedium: const TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w500,
                  ),
                  headlineLarge: TextStyle(
                    fontFamily: "Alex",
                    fontSize: 32.sp,
                    fontWeight: FontWeight.w500,
                  )),
            ),
            debugShowCheckedModeBanner: false,
            title: "SpoonApp",
            home: child,
          );
        },
        child: MobileWelcomeScreen(),
      );
    }
    
    Login or Signup to reply.
  2. Please add this parameter, minTextAdapt: true, // Here, provide a value for minTextAdapt

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search