flutter 发现意外的空值

ghhkc1vu  于 2023-10-22  发布在  Flutter
关注(0)|答案(2)|浏览(171)

我尝试运行我的flutter应用程序,运行后显示意外的空值,在调试控制台上显示问题出在AppText上。enText 'welcome Text:']!,附件是auth_page类和apptext类的代码

import 'package:flutter/material.dart';
import 'package:laravel/components/login.dart';
import 'package:laravel/utils/config.dart';
import 'package:laravel/utils/text.dart';

class authPage extends StatefulWidget {
  const authPage({Key? key}) : super(key: key);
  @override
  State<authPage> createState() => _authPage();
}

class _authPage extends State<authPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
          child: SafeArea(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  AppText.enText['welcome Text:']!,
                  style: const TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 36,
                  ),
                ),
                Config.spaceSmall,

                Text(
                  AppText.enText['signIn Text:']!,
                  style: const TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 16,
                  ),
                ),
                Config.spaceSmall,

                //login components here
                loginForm(),
                Config.spaceSmall,
                Center(
                  child: TextButton(
                    onPressed: () {},
                    child: Text(
                      AppText.enText['Forgot Password']!,
                      style: const TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                      ),
                    ),
                  ),
                )

                //18
              ],
            ),
          )),
    );
  }
}

```//
the apptext class//

//class AppText class AppText { static final enText = { 'welcome Text':“欢迎”、“登录文本”:'登录到您的帐户','注册文本':“已经有一个Acount”,“注册文本”:“您可以轻松注册并连接到您附近的医生”,“注册文本”:没有账号?','社交登录':'或继续使用社交帐户','忘记密码':'忘记密码',};}

I tried running the app but a red screen appeared showing unexpected null value
3qpi33ja

3qpi33ja1#

很明显,AppText.enText不包含像welcome Text:signIn Text:这样的键,用welcome Text替换welcome Text:,用signIn Text替换signIn Text:

yi0zb3m4

yi0zb3m42#

您可以尝试以下代码进行调试:

Text(
    AppText.enText['welcome Text:'] ?? " Your Default Text",
    style: const TextStyle(
        fontWeight: FontWeight.bold,
        fontSize: 36,
    ),
),

相关问题