要在Flutter中显示一个Alert框,你可以使用flutter的原生对话框,如下所示:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Alert Dialog'),
),
body: Center(
child: RaisedButton(
child: Text('Show Alert'),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Alert'),
content: Text('This is an alert dialog.'),
actions: [
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
},
),
),
),
);
}
}
在这个例子中,我们创建了一个简单的Flutter应用,当用户点击按钮时,会显示一个Alert对话框。Alert对话框包含一个标题、内容和一个OK按钮。当用户点击OK按钮时,对话框会被关闭。
你可以根据你的需要自定义对话框的样式和内容,使用Flutter提供的各种对话框组件。
上一篇:Alertasyncinview
下一篇:alert不显示域名