Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- visualDensity: VisualDensity.adaptivePlatformDensity,
- ),
- home: MainPage(),
- );
- }
- }
- class MainPage extends StatefulWidget {
- const MainPage({Key key}) : super(key: key);
- @override
- _MainPageState createState() => _MainPageState();
- }
- class _MainPageState extends State<MainPage> {
- bool _confirmed;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text("Confirmation: $_confirmed"),
- SizedBox(height: 48),
- OutlineButton(
- onPressed: () async {
- bool confirmed = await showDialog<bool>(
- context: context,
- builder: (context) => ConfirmationDialog());
- setState(() {
- _confirmed = confirmed;
- });
- },
- child: Text("Show Confirm Popup"),
- ),
- ],
- ),
- ),
- );
- }
- }
- class ConfirmationDialog extends StatelessWidget {
- const ConfirmationDialog({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return AlertDialog(
- title: Text("confirm"),
- content: Text("Do you confirm"),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(context, true), child: Text("Yes")),
- TextButton(
- onPressed: () => Navigator.pop(context, false), child: Text("No")),
- ],
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement