【问题标题】:Null check operator used on a null value Error用于空值错误的空检查运算符
【发布时间】:2021-12-08 15:44:48
【问题描述】:

这个问题的原因是什么? 当我点击按钮显示 toast 时,会出现此消息

在处理手势时引发以下 _CastError: 用于空值的空检查运算符

*当异常被抛出时,这是堆栈: showToastWidget(包:flutter_styled_toast/src/styled_toast.dart:268:22)

 home: Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            showToast(txt,
                context: context,
                animation: StyledToastAnimation.slideFromLeft,
                reverseAnimation: StyledToastAnimation.slideToBottom,
                position: StyledToastPosition(
                align: Alignment.bottomCenter, offset: 55),
                animDuration: Duration(milliseconds: 300),
                duration: Duration(seconds: 2),
                curve: Curves.easeInOutBack,
                reverseCurve: Curves.elasticIn,
                backgroundColor: Color.fromRGBO(191, 21, 35, 0.5),
                textStyle: TextStyle(fontSize: 20, color: Colors.white));
          },
          child: const Icon(Icons.add),
        ),
        appBar: AppBar(title: Text('Flutter Code Sample')),
        body: const Center(
          child: MyStatelessWidget(),
        ),
      ),
    );
  }
}

【问题讨论】:

  • 你能不能把homeScaffold分开在不同的widget上再试一次。
  • 什么是txt?你能发一个minimal reproducible example吗?
  • 谢谢,已经解决@YeasinSheikh
  • @nvoigt txt 在图片中
  • 你可以阅读它here

标签: flutter dart


【解决方案1】:

答案:


import 'package:flutter/material.dart';

import 'dialogPage.dart';

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

/// This is the main application widget.
class MyApp extends StatelessWidget {

  MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home:DialogPage() ,
    );
  }
}
   return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          showToast(txt,
              context: context,
              animation: StyledToastAnimation.slideFromLeft,
              reverseAnimation: StyledToastAnimation.slideToBottom,
              position: const StyledToastPosition(
                  align: Alignment.bottomCenter, offset: 55),
              animDuration: Duration(milliseconds: 300),
              duration: const Duration(seconds: 2),
              curve: Curves.easeInOutBack,
              reverseCurve: Curves.elasticIn,
              backgroundColor: Color.fromRGBO(191, 21, 35, 0.5),
              textStyle: TextStyle(fontSize: 20, color: Colors.white));
        },
        child: const Icon(Icons.add),
      ),
      appBar: AppBar(title: Text('Flutter Code Sample')),
      body: const Center(
        child: MyStatelessWidget(),
      ),
    );

【讨论】:

  • 你能解释一下你改变了什么吗?
  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。
猜你喜欢
  • 2021-11-04
  • 2022-06-19
  • 2021-09-01
  • 2022-08-06
  • 1970-01-01
  • 1970-01-01
  • 2021-01-24
  • 2022-07-06
  • 2021-12-03
相关资源
最近更新 更多