-
Notifications
You must be signed in to change notification settings - Fork 61
/
main.dart
166 lines (145 loc) · 5.06 KB
/
main.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
159
160
161
162
163
164
165
import 'package:flutter/material.dart';
import 'package:string_scanner/string_scanner.dart';
void main() => runApp(MyApp());
const testStr = '''
/**
* Created with Android Studio.
* User: 一晟
* Date: 2018/11/22
* Time: 上午12:03
* email: zhu.yan@alibaba-inc.com
* tartget: FlatButton 的示例
*/
import 'dart:math';
import 'package:flutter/material.dart';
// FlatButton 默认按钮的实例
// isDisabled:是否是禁用,isDisabled 默认为true
class FlatButtonDefault extends StatelessWidget {
final bool isDisabled;
const FlatButtonDefault([ this.isDisabled = true])
: assert(isDisabled != null),
super();
@override
Widget build(BuildContext context) {
return FlatButton(
// 文本内容
child: const Text('默认按钮', semanticsLabel: 'FLAT BUTTON 1'),
onPressed: isDisabled ? () {} : null);
}
}
// FlatButton.icon 默认按钮的实例
// * Create a text button from a pair of widgets that serve as the button's icon and label
// * isDisabled:是否是禁用
class FlatButtonIconDefault extends StatelessWidget {
final bool isDisabled;
final IconData icon;
const FlatButtonIconDefault(
[ this.isDisabled = true, this.icon = Icons.add_circle])
: super();
Color _randomColor() {
var red = Random.secure().nextInt(255);
var greed = Random.secure().nextInt(255);
var blue = Random.secure().nextInt(255);
return Color.fromARGB(255, red, greed, blue);
}
@override
Widget build(BuildContext context) {
return FlatButton.icon(
// 文本内容
icon: Icon(icon, size: 25.0, color: _randomColor()),
label: Text('默认按钮', semanticsLabel: 'FLAT BUTTON 2'),
onPressed: isDisabled
? () {
//_showMessage('点击了 FLAT BUTTON ', context);
}
: null);
}
}
// FlatButton 自定义的实例
class FlatButtonCustom extends StatelessWidget {
final String txt;
final Color color;
final ShapeBorder shape;
final VoidCallback onPressed;
const FlatButtonCustom([
this.txt = '自定义按钮',
this.color = Colors.blueAccent,
this.shape,
this.onPressed
]) :super();
@override
Widget build(BuildContext context) {
final _onPressed = onPressed;
return FlatButton(
// 文本内容
child: Text(txt, semanticsLabel: 'FLAT BUTTON 2'),
// 按钮颜色
color: color,
// 按钮亮度
colorBrightness: Brightness.dark,
// 高亮时的背景色
//highlightColor: Colors.yellow,
// 失效时的背景色
disabledColor: Colors.grey,
// 该按钮上的文字颜色,但是前提是不设置字体自身的颜色时才会起作用
textColor: Colors.white,
// 按钮失效时的文字颜色,同样的不能使用文本自己的样式或者颜色时才会起作用
disabledTextColor: Colors.grey,
// 按钮主题,主要用于与ButtonTheme和ButtonThemeData一起使用来定义按钮的基色,RaisedButton,FlatButton,OutlineButton,它们是基于环境ButtonTheme配置的
//ButtonTextTheme.accent,使用模版颜色的;ButtonTextTheme.normal,按钮文本是黑色或白色取决于。ThemeData.brightness;ButtonTextTheme.primary,按钮文本基于。ThemeData.primaryColor.
textTheme: ButtonTextTheme.normal,
// 按钮内部,墨汁飞溅的颜色,点击按钮时的渐变背景色,当你不设置高亮背景时才会看的更清楚
splashColor: Colors.deepPurple,
// 抗锯齿能力,抗锯齿等级依次递增,none(默认),hardEdge,antiAliasWithSaveLayer,antiAlias
clipBehavior: Clip.antiAlias,
padding: new EdgeInsets.only(
bottom: 5.0, top: 5.0, left: 30.0, right: 30.0),
shape: (shape is ShapeBorder) ? shape : new Border.all(
// 设置边框样式
color: Colors.grey,
width: 2.0,
style: BorderStyle.solid,
),
// FlatButton 的点击事件
onPressed: () {
// Perform some action
if (_onPressed is VoidCallback) {
_onPressed();
}
},
// 改变高亮颜色回掉函数,一个按钮会触发两次,按下后改变时触发一次,松手后恢复原始颜色触发一次
// 参数 bool,按下后true,恢复false
onHighlightChanged: (isClick) {
print(isClick);
}
);
}
}
''';
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
StringScanner _scanner = StringScanner(testStr);
@override
Widget build(BuildContext context) {
print('$_scanner');
print('${_scanner.scan(RegExp(r'/\*(.|\n)*\*/'))}');
return Container(
child: Text('test'),
);
}
}