-
Notifications
You must be signed in to change notification settings - Fork 107
/
alert_dialog.dart
126 lines (109 loc) · 3.67 KB
/
alert_dialog.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'diagram_step.dart';
import 'utils.dart';
const Duration _pauseDuration = Duration(seconds: 1);
const Duration _openDuration = Duration(milliseconds: 300);
final Duration _totalDuration = _pauseDuration + _openDuration + _pauseDuration;
class AlertDialogDiagram extends StatefulWidget with DiagramMetadata {
const AlertDialogDiagram(this.name, {super.key});
@override
final String name;
@override
State<AlertDialogDiagram> createState() => _AlertDialogDiagramState();
@override
Duration? get duration => _totalDuration;
}
class _AlertDialogDiagramState extends State<AlertDialogDiagram>
with TickerProviderStateMixin, LockstepStateMixin {
final GlobalKey _openDialogKey = GlobalKey();
Future<void> startAnimation() async {
await waitLockstep(_pauseDuration);
final RenderBox target =
_openDialogKey.currentContext!.findRenderObject()! as RenderBox;
final Offset targetOffset = target.localToGlobal(
target.size.center(Offset.zero),
);
final WidgetController controller = DiagramWidgetController.of(context);
final TestGesture gesture = await controller.startGesture(targetOffset);
await waitLockstep(_openDuration);
await gesture.up();
}
@override
void initState() {
super.initState();
startAnimation();
}
@override
Widget build(BuildContext context) {
return ConstrainedBox(
key: UniqueKey(),
constraints: BoxConstraints.tight(const Size(350, 622)),
child: Navigator(
initialRoute: '/',
onGenerateRoute: (RouteSettings settings) {
return PageRouteBuilder<void>(
pageBuilder: (
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) {
return Scaffold(
appBar: AppBar(title: const Text('AlertDialog Demo')),
body: Center(
child: Builder(
builder: (BuildContext context) {
return OutlinedButton(
key: _openDialogKey,
child: const Text('Show Dialog'),
onPressed: () => _neverSatisfied(context),
);
},
),
),
);
},
);
},
),
);
}
Future<void> _neverSatisfied(BuildContext context) async {
return showDialog<void>(
context: context,
useRootNavigator: false,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('AlertDialog'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('This is a demo alert dialog.'),
Text('Would you like to approve of this message?'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('Approve'),
onPressed: () => Navigator.of(context).pop(),
),
],
);
},
);
}
}
class AlertDialogDiagramStep extends DiagramStep {
@override
final String category = 'material';
@override
Future<List<AlertDialogDiagram>> get diagrams async => <AlertDialogDiagram>[
const AlertDialogDiagram('alert_dialog'),
];
}