forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_bar.dart
135 lines (123 loc) · 4.45 KB
/
app_bar.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
// 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:async';
import 'dart:io';
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
import 'utils.dart';
class AppBarDiagram extends StatefulWidget implements DiagramMetadata {
const AppBarDiagram({Key? key, required this.name}) : super(key: key);
@override
final String name;
@override
State<AppBarDiagram> createState() => _DiagramState();
}
class _DiagramState extends State<AppBarDiagram> {
final GlobalKey leading = GlobalKey();
final GlobalKey actions = GlobalKey();
final GlobalKey title = GlobalKey();
final GlobalKey flexibleSpace = GlobalKey();
final GlobalKey bottom = GlobalKey();
final GlobalKey heroKey = GlobalKey();
final GlobalKey canvasKey = GlobalKey();
@override
Widget build(BuildContext context) {
return ConstrainedBox(
key: UniqueKey(),
constraints: BoxConstraints.tight(const Size(
540.0,
260.0,
)),
child: Theme(
data: ThemeData(
primarySwatch: Colors.blue,
),
child: Material(
color: const Color(0xFFFFFFFF),
child: MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.zero,
),
child: Stack(
children: <Widget>[
Center(
child: SizedBox(
width: 300.0,
height: kToolbarHeight * 2.0 + 50.0,
child: AppBar(
key: heroKey,
leading: Hole(key: leading),
title: Text('Abc', key: title),
actions: <Widget>[
const Hole(),
const Hole(),
Hole(key: actions),
],
flexibleSpace: DecoratedBox(
key: flexibleSpace,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: FractionalOffset.topCenter,
end: const FractionalOffset(0.48, 1.0),
colors: <Color>[
Colors.blue.shade500,
Colors.blue.shade800
],
),
),
),
bottom: PreferredSize(
key: bottom,
preferredSize: const Size(0.0, kToolbarHeight),
child: Container(
height: 50.0,
padding: const EdgeInsets.all(4.0),
child: const Placeholder(
strokeWidth: 2.0,
color: Color(0xFFFFFFFF),
),
),
),
),
),
),
Positioned.fill(
child: LabelPainterWidget(
key: canvasKey,
labels: <Label>[
Label(leading, 'leading',
const FractionalOffset(0.5, 0.25)),
Label(actions, 'actions',
const FractionalOffset(0.25, 0.5)),
Label(title, 'title', FractionalOffset.center),
Label(flexibleSpace, 'flexibleSpace',
const FractionalOffset(0.2, 0.5)),
Label(
bottom, 'bottom', const FractionalOffset(0.5, 0.75)),
],
heroKey: heroKey,
),
),
],
),
),
),
),
);
}
}
class AppBarDiagramStep extends DiagramStep<AppBarDiagram> {
AppBarDiagramStep(DiagramController controller) : super(controller);
@override
final String category = 'material';
@override
Future<List<AppBarDiagram>> get diagrams async =>
<AppBarDiagram>[const AppBarDiagram(name: 'app_bar')];
@override
Future<File> generateDiagram(AppBarDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
return controller.drawDiagramToFile(File('${diagram.name}.png'));
}
}