Dman_14

Untitled

Jan 20th, 2021
935
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       title: 'Flutter Demo',
  12.       theme: ThemeData(
  13.         primarySwatch: Colors.blue,
  14.         visualDensity: VisualDensity.adaptivePlatformDensity,
  15.       ),
  16.       home: MainPage(),
  17.     );
  18.   }
  19. }
  20.  
  21. class MainPage extends StatefulWidget {
  22.   const MainPage({Key key}) : super(key: key);
  23.  
  24.   @override
  25.   _MainPageState createState() => _MainPageState();
  26. }
  27.  
  28. class _MainPageState extends State<MainPage> {
  29.   bool _confirmed;
  30.  
  31.   @override
  32.   Widget build(BuildContext context) {
  33.     return Scaffold(
  34.       body: Center(
  35.         child: Column(
  36.           mainAxisAlignment: MainAxisAlignment.center,
  37.           children: [
  38.             Text("Confirmation: $_confirmed"),
  39.             SizedBox(height: 48),
  40.             OutlineButton(
  41.               onPressed: () async {
  42.                 bool confirmed = await showDialog<bool>(
  43.                     context: context,
  44.                     builder: (context) => ConfirmationDialog());
  45.  
  46.                 setState(() {
  47.                   _confirmed = confirmed;
  48.                 });
  49.               },
  50.               child: Text("Show Confirm Popup"),
  51.             ),
  52.           ],
  53.         ),
  54.       ),
  55.     );
  56.   }
  57. }
  58.  
  59. class ConfirmationDialog extends StatelessWidget {
  60.   const ConfirmationDialog({Key key}) : super(key: key);
  61.  
  62.   @override
  63.   Widget build(BuildContext context) {
  64.     return AlertDialog(
  65.       title: Text("confirm"),
  66.       content: Text("Do you confirm"),
  67.       actions: [
  68.         TextButton(
  69.             onPressed: () => Navigator.pop(context, true), child: Text("Yes")),
  70.         TextButton(
  71.             onPressed: () => Navigator.pop(context, false), child: Text("No")),
  72.       ],
  73.     );
  74.   }
  75. }
  76.  
RAW Paste Data