断言错误('package:flutter/src/material/button_bar_theme.dart':失败的断言:第 253 行 pos 16:"data != null":不为真。



当我试图将文本输入到flutter应用程序时,我无法移动到下一个屏幕并收到此错误。我甚至考虑过一些其他解决方案来解决之前提出的类似问题,但对我来说不起作用。以下是引发错误的buttonbartheme类的代码。

class ButtonBarTheme extends InheritedWidget {
/// Constructs a button bar theme that configures all descendent [ButtonBar]
/// widgets.
///
/// The [data] must not be null.
const ButtonBarTheme({
Key? key,
required this.data,
required Widget child,
})  : assert(data != null), <- ERROR
super(key: key, child: child);
final ButtonBarThemeData data; 
/// Returns the configuration [data] from the closest [ButtonBarTheme]
/// ancestor. If there is no ancestor, it returns [ThemeData.buttonBarTheme].
/// Applications can assume that the returned value will not be null.
///
/// Typical usage is as follows:
///
/// ```dart
/// ButtonBarThemeData theme = ButtonBarTheme.of(context);
/// ```
static ButtonBarThemeData of(BuildContext context) {
final ButtonBarTheme? buttonBarTheme =
context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>();
return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme;
}

我在仪表板和其他屏幕中使用Buttonbartheme,如下所示:

ButtonBarTheme(
// makes buttons use the appropriate styles for cards
data: null,
child: ButtonBar(
children: <Widget>[
TextButton(
child: const Text('Share'),
onPressed: () {
// ignore: todo
//TODO Implement share to social media
},
),
TextButton(
child: const Text('Dismiss'),
onPressed: () {
client.show1 = false;
update(client);
},
),
],
),
),

Do:

ButtonBarTheme(
data: ButtonBarThemeData(),
child: //rest of code
) 

相关内容