1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6import '../utils.dart';
7import 'use_cases.dart';
8
9class DialogUseCase extends UseCase {
10 @override
11 String get name => 'Dialog';
12
13 @override
14 String get route => '/dialog';
15
16 @override
17 Widget build(BuildContext context) => _MainWidget();
18}
19
20class _MainWidget extends StatelessWidget {
21 _MainWidget();
22
23 final String pageTitle = getUseCaseName(DialogUseCase());
24
25 @override
26 Widget build(BuildContext context) {
27 return Scaffold(
28 appBar: AppBar(
29 backgroundColor: Theme.of(context).colorScheme.inversePrimary,
30 title: Semantics(headingLevel: 1, child: Text('$pageTitle Demo')),
31 ),
32 body: Center(
33 child: TextButton(
34 onPressed: () => showDialog<String>(
35 context: context,
36 builder: (BuildContext context) => Dialog(
37 child: Padding(
38 padding: const EdgeInsets.all(8.0),
39 child: Column(
40 mainAxisSize: MainAxisSize.min,
41 mainAxisAlignment: MainAxisAlignment.center,
42 children: <Widget>[
43 const Text('This is a typical dialog.'),
44 const SizedBox(height: 15),
45 Row(
46 children: <Widget>[
47 TextButton(
48 key: const Key('OK Button'),
49 autofocus: true,
50 onPressed: () {
51 Navigator.pop(context);
52 },
53 child: const Text('OK'),
54 ),
55 TextButton(
56 onPressed: () {
57 Navigator.pop(context);
58 },
59 child: const Text('Cancel'),
60 ),
61 ],
62 ),
63 ],
64 ),
65 ),
66 ),
67 ),
68 child: const Text('Show Dialog'),
69 ),
70 ),
71 );
72 }
73}
74