forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawer.dart
136 lines (119 loc) · 4.36 KB
/
drawer.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
127
128
129
130
131
132
133
134
135
136
// 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 'dart:io';
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'diagram_step.dart';
const Duration _pauseDuration = Duration(seconds: 1);
const Duration _drawerOpenDuration = Duration(milliseconds: 300);
final Duration _totalDuration =
_pauseDuration + _drawerOpenDuration + _pauseDuration;
final GlobalKey _menuKey = GlobalKey();
class DrawerDiagram extends StatelessWidget implements DiagramMetadata {
const DrawerDiagram(this.name, {Key? key}) : super(key: key);
@override
final String name;
@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 Container(
alignment: FractionalOffset.center,
color: Colors.white,
child: Scaffold(
appBar: AppBar(
title: const Text('Drawer Demo'),
automaticallyImplyLeading: false,
leading: Builder(
builder: (BuildContext context) {
return IconButton(
key: _menuKey,
icon: const Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openDrawer();
},
);
},
),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: const <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text(
'Drawer Header',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
ListTile(
leading: Icon(Icons.message),
title: Text('Messages'),
),
ListTile(
leading: Icon(Icons.account_circle),
title: Text('Profile'),
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
),
],
),
),
),
);
},
);
},
),
);
}
}
class DrawerDiagramStep extends DiagramStep<DrawerDiagram> {
DrawerDiagramStep(DiagramController controller) : super(controller);
@override
final String category = 'material';
@override
Future<List<DrawerDiagram>> get diagrams async => <DrawerDiagram>[
const DrawerDiagram('drawer'),
];
@override
Future<File> generateDiagram(DrawerDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
controller.advanceTime(Duration.zero);
final Future<File> result = controller.drawAnimatedDiagramToFiles(
end: _totalDuration,
frameRate: 60,
name: diagram.name,
category: category,
);
await Future<void>.delayed(_pauseDuration);
final RenderBox target =
_menuKey.currentContext!.findRenderObject()! as RenderBox;
final Offset targetOffset =
target.localToGlobal(target.size.center(Offset.zero));
final TestGesture gesture = await controller.startGesture(targetOffset);
await gesture.up();
await Future<void>.delayed(_drawerOpenDuration + _pauseDuration);
return result;
}
}