我正在尝试显示警报。我正在使用rflutter包。但这不起作用,我不明白。
我正在尝试显示警报。我正在使用rflutter包。但这不起作用,我不明白。
这是我的main.dart
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
void main() => runApp(DialogueBoxes());
class DialogueBoxes extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.green,
home: Scaffold(
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Text("Click Flat"),
onPressed: () {
return Alert(
context: context,
title: 'Flat Cilcked',
).show();
},
),
RaisedButton(
child: Text("Click Raised"),
onPressed: () => Alert(
context: context,
title: 'Raised Click',
).show(),
)
],
),
),
),
),
);
}
}
这是pubspec.yaml依赖项
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
rflutter_alert: ^1.0.3
这是我遇到的错误。
E/flutter (27156): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The getter 'modalBarrierDismissLabel' was called on null.
E/flutter (27156): Receiver: null
E/flutter (27156): Tried calling: modalBarrierDismissLabel
E/flutter (27156): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (27156): #1 Alert.show (package:rflutter_alert/src/alert.dart:54:55)
E/flutter (27156): <asynchronous suspension>
E/flutter (27156): #2 DialogueBoxes.build.<anonymous closure> (package:quizzed/main.dart:32:21)
E/flutter (27156): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
E/flutter (27156): #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32)
E/flutter (27156): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (27156): #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (27156): #7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter (27156): #8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter (27156): #9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter (27156): #10 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter (27156): #11 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (27156): #12 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (27156): #13 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (27156): #14 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (27156): #15 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (27156): #16 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (27156): #17 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (27156): #18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (27156): #19 _invoke1 (dart:ui/hooks.dart:263:10)
E/flutter (27156): #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)
E/flutter (27156):
答案 0 :(得分:0)
您需要拆分家庭小部件,尝试将Scaffold
切换到另一个StatelessWidget
,然后从MaterialApp home
调用它
编辑
像这样MaterialApp
home: home()
家
这是您在另一个Scaffold
中的新home() StatelessWidget
class home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Text("Click Flat"),
onPressed: () {
return Alert(
context: context,
title: 'Flat Cilcked',
).show();
},
),
RaisedButton(
child: Text("Click Raised"),
onPressed: () => Alert(
context: context,
title: 'Raised Click',
).show(),
)
],
),
),
),
);
}
}
答案 1 :(得分:0)
您的问题看起来像不是引用上下文参数。
尝试一下。
RaisedButton(
child : Text("Click Raised),
onPressed : () => _showAlert(context),
)
...
//Out of build method
_showAlert(context){
Alert(
context : context,
title : 'Raised Click',
).show();
}