flutter 错误:延迟初始化错误:字段'_splitScreenMode@963084504'尚未初始化

piv4azn7  于 2022-12-14  发布在  Flutter
关注(0)|答案(1)|浏览(379)

我得到了错误:“延迟初始化错误:字段'_splitScreenMode@963084504'尚未初始化”,当我尝试创建第二页(启动后的下一页,名称为:pageOne)通过导入flutter_screen_util包进行响应。我添加了.w和.h用于宽度和高度测量。我是flutter新手,所以我不能识别此错误。
我的启动画面代码:

import 'package:flutter/material.dart';

import 'package:my_wallet/screens/categories.dart';

import 'package:my_wallet/screens/page_1.dart';

class ScreenSplash extends StatefulWidget {
  const ScreenSplash({Key? key}) : super(key: key);

  @override
  State<ScreenSplash> createState() => _ScreenSplashState();
}

class _ScreenSplashState extends State<ScreenSplash> {
  @override
  void initState() {
    checkUser(context);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.bottomCenter,
          end: Alignment.topRight,
          colors: [
            Color.fromARGB(255, 0, 27, 48),
            Color.fromARGB(255, 17, 149, 186),
          ],
        ),
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: Center(
          child: Image.asset(
            'lib/assets/coin-spin3.gif',
            height: 180,
          ),
        ),
      ),
    );
  }
}

Future<void> checkUser(context) async {
  await Future.delayed(
    const Duration(seconds: 4),
  );
  Navigator.of(context).pushReplacement(
    MaterialPageRoute(
      // builder: (ctx) => const PageOne(),
      builder: (ctx) => const PageOne(),
    ),
  );
}

我的pageOne(启动后的屏幕)代码:

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:my_wallet/screens/page_2.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          height: double.infinity,
          decoration: const BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.bottomLeft,
              end: Alignment.topRight,
              colors: [
                Color.fromARGB(255, 0, 27, 48),
                Color.fromARGB(255, 17, 149, 186),
              ],
            ),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              SizedBox(
                height: 220.h,
                child: const Image(
                  image: AssetImage(
                    'lib/assets/moneymanagement1.png',
                  ),
                ),
              ),
              const SizedBox(
                height: 70,
              ),
              const Text(
                'Track Your Expense',
                style: TextStyle(
                    color: Color.fromARGB(255, 255, 255, 255), fontSize: 25),
              ),
              const SizedBox(
                height: 100,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  const CircleAvatar(
                    backgroundColor: Color.fromARGB(255, 255, 255, 255),
                    radius: 4.5,
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  const CircleAvatar(
                    backgroundColor: Color.fromARGB(255, 104, 104, 104),
                    radius: 4.5,
                  ),
                  const SizedBox(
                    width: 120,
                  ),
                  IconButton(
                    onPressed: (() {
                      Navigator.of(context).pushReplacement(
                        MaterialPageRoute(
                          builder: (ctx1) => const PageTwo(),
                        ),
                      );
                    }),
                    icon: const Icon(
                      Icons.arrow_forward_ios,
                      color: Colors.white,
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                ],
              ),
              const SizedBox(
                height: 40,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
g52tjvyc

g52tjvyc1#

您是否按照https://pub.dev/packages/flutter_screenutil自述文件部分的步骤在main.dart中设置了“ScreenUtilInit”的代码?

相关问题