forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_mode.dart
158 lines (142 loc) · 4.66 KB
/
tile_mode.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright 2017 The Chromium 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 'dart:math' as math;
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
const double topPadding = 30.0;
const double width = 190.0;
const double height = 200.0;
const double spacing = 8.0;
const double borderSize = 1.0;
enum GradientMode {
linear,
radial,
radialWithFocal,
sweep,
}
class TileModeDiagram extends StatelessWidget implements DiagramMetadata {
const TileModeDiagram(this.gradientMode, this.tileMode);
@override
String get name => 'tile_mode_${describeEnum(tileMode)}_${describeEnum(gradientMode)}';
final GradientMode gradientMode;
final TileMode tileMode;
String get gradientModeName {
final String s = describeEnum(gradientMode);
return s[0].toUpperCase() + s.substring(1);
}
Gradient _buildGradient() {
Gradient gradient;
switch (gradientMode) {
case GradientMode.linear:
gradient = LinearGradient(
begin: const FractionalOffset(0.4, 0.5),
end: const FractionalOffset(0.6, 0.5),
colors: const <Color>[Color(0xFF0000FF), Color(0xFF00FF00)],
stops: const <double>[0.0, 1.0],
tileMode: tileMode,
);
break;
case GradientMode.radial:
gradient = RadialGradient(
center: FractionalOffset.center,
radius: 0.2,
colors: const <Color>[Color(0xFF0000FF), Color(0xFF00FF00)],
stops: const <double>[0.0, 1.0],
tileMode: tileMode,
);
break;
case GradientMode.sweep:
gradient = SweepGradient(
center: FractionalOffset.center,
startAngle: 0.0,
endAngle: math.pi / 2,
colors: const <Color>[Color(0xFF0000FF), Color(0xFF00FF00)],
stops: const <double>[0.0, 1.0],
tileMode: tileMode,
);
break;
case GradientMode.radialWithFocal:
gradient = RadialGradient(
center: FractionalOffset.center,
focal: const FractionalOffset(0.5, 0.42),
radius: 0.2,
colors: const <Color>[Color(0xFF0000FF), Color(0xFF00FF00)],
stops: const <double>[0.0, 1.0],
tileMode: tileMode,
);
break;
}
return gradient;
}
@override
Widget build(BuildContext context) {
return ConstrainedBox(
key: UniqueKey(),
constraints: const BoxConstraints.tightFor(width: width, height: height),
child: DefaultTextStyle.merge(
style: const TextStyle(
fontSize: 10.0,
color: Color(0xFF000000),
),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
margin: const EdgeInsets.all(spacing),
width: width,
decoration: BoxDecoration(
border: Border.all(width: borderSize),
color: const Color(0xFFFFFFFF),
),
child: Column(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: _buildGradient(),
border: const Border(
bottom: BorderSide(width: 1.0),
),
),
),
),
Container(height: 3.0),
Text(
'$gradientModeName Gradient',
textAlign: TextAlign.center,
),
Text('$tileMode', textAlign: TextAlign.center),
Container(height: 3.0),
],
),
),
),
),
),
);
}
}
class TileModeDiagramStep extends DiagramStep<TileModeDiagram> {
TileModeDiagramStep(DiagramController controller) : super(controller) {
for (final TileMode mode in TileMode.values) {
for (final GradientMode gradient in GradientMode.values) {
_diagrams.add(TileModeDiagram(gradient, mode));
}
}
}
@override
final String category = 'dart-ui';
final List<TileModeDiagram> _diagrams = <TileModeDiagram>[];
@override
Future<List<TileModeDiagram>> get diagrams async => _diagrams;
@override
Future<File> generateDiagram(TileModeDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
return await controller.drawDiagramToFile(File('${diagram.name}.png'));
}
}