Skip to content

Commit ef31ad4

Browse files
committed
Add: Progress widget color style
1 parent 5f98ea0 commit ef31ad4

File tree

4 files changed

+200
-3
lines changed

4 files changed

+200
-3
lines changed

lib/component/main/MainPage.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class _MainState extends State<MainPage> {
6262
"RichText",
6363
"Progress",
6464
"Segment",
65+
"DropDown",
6566
];
6667
return _sortTitles;
6768
}
@@ -84,6 +85,7 @@ class _MainState extends State<MainPage> {
8485
"/RichTextPage",
8586
"/MainProgressPage",
8687
"/SegmentPage",
88+
"/DropDownPage",
8789
];
8890
return _sortRouteNames;
8991
}

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import 'sample/clip/clip_main_page.dart';
3434
import 'sample/navigation/curved_navigation_bar_page.dart';
3535
import 'sample/picker/main_picker_page.dart';
3636
import 'sample/progress/main_progress_page.dart';
37+
import 'sample/segment/drop_down_page.dart';
3738
import 'sample/segment/segment_page.dart';
3839
import 'sample/text/RichTextPage.dart';
3940
import 'sample/tip/flushbar_page.dart';
@@ -118,6 +119,7 @@ class Test extends StatelessWidget {
118119
"/RichTextPage": (_) => RichTextPage(),
119120
"/MainProgressPage": (_) => MainProgressPage(),
120121
"/SegmentPage": (_) => SegmentPage(),
122+
"/DropDownPage": (_) => DropDownPage(),
121123
},
122124
);
123125
},

lib/sample/progress/main_progress_page.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class _MainProgressState extends State<MainProgressPage>
2121
double _slideValue = MAX;
2222

2323
AnimationController _controller;
24-
Animation _colorTween;
24+
Animation<Color> _colorTween;
2525

2626
@override
2727
void initState() {
@@ -55,6 +55,7 @@ class _MainProgressState extends State<MainProgressPage>
5555
label: "$_slideValue",
5656
divisions: _divisions,
5757
value: _slideValue,
58+
activeColor: _colorTween.value,
5859
onChanged: (double value) {
5960
setState(() {
6061
_slideValue = value.ceilToDouble();
@@ -63,7 +64,6 @@ class _MainProgressState extends State<MainProgressPage>
6364
});
6465
},
6566
),
66-
Spacer(),
6767
Stack(
6868
alignment: Alignment.center,
6969
children: <Widget>[
@@ -80,7 +80,21 @@ class _MainProgressState extends State<MainProgressPage>
8080
Text("$_slideValue/%"),
8181
],
8282
),
83-
Spacer(),
83+
Slider(
84+
min: MIN,
85+
max: MAX,
86+
label: "$_slideValue",
87+
divisions: _divisions,
88+
value: _slideValue,
89+
activeColor: _colorTween.value,
90+
onChanged: (double value) {
91+
setState(() {
92+
_slideValue = value.ceilToDouble();
93+
_progressValue = (value / 100);
94+
_controller.value = _progressValue;
95+
});
96+
},
97+
),
8498
LinearProgressIndicator(
8599
value: _progressValue,
86100
valueColor: _colorTween,
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import 'package:flutter/material.dart';
2+
3+
enum Commands { heroAndScholar, hurricaneCame }
4+
5+
///
6+
/// DropDownPage
7+
class DropDownPage extends StatefulWidget {
8+
@override
9+
State<StatefulWidget> createState() {
10+
return _DropState();
11+
}
12+
}
13+
14+
///
15+
/// _DropState
16+
class _DropState extends State<DropDownPage> {
17+
String dropdownValue = 'One';
18+
19+
//实例变量(非静态变量)可以是final但不能是const
20+
//const不能修饰实例变量
21+
//final可以修饰实例变量
22+
23+
//const不仅能修饰'类变量',还可以修饰'变量值';
24+
//特殊:constVar 可以修改值(const [1,2,3]此时不可被修改值,也就是等同于是'数组')
25+
var constVar = const [1, 2, 3];
26+
27+
//特殊:pra 不可以修改值
28+
static const pra = "";
29+
30+
final String parame = "";
31+
32+
List<String> _dropDownItems = [
33+
'One',
34+
'Two',
35+
'Free',
36+
'Four',
37+
];
38+
39+
bool _heroAndScholar = false;
40+
41+
@override
42+
Widget build(BuildContext context) {
43+
//constVar.add(5);//Error -> 'Unsupported operation: Cannot add to an unmodifiable list'
44+
constVar = [1, 23];
45+
constVar.sort();
46+
47+
return Scaffold(
48+
appBar: AppBar(
49+
title: Text("DropDown"),
50+
),
51+
body: Row(
52+
children: <Widget>[
53+
Spacer(),
54+
Column(
55+
children: <Widget>[
56+
Spacer(),
57+
DropdownButton<String>(
58+
isExpanded: false,
59+
isDense: false,
60+
value: dropdownValue,
61+
onChanged: (String newValue) {
62+
setState(() {
63+
dropdownValue = newValue;
64+
});
65+
},
66+
icon: Icon(Icons.arrow_downward),
67+
iconSize: 24,
68+
elevation: 2,
69+
style: TextStyle(color: Colors.deepPurple),
70+
underline: Container(
71+
height: 2,
72+
color: Colors.deepPurpleAccent,
73+
),
74+
selectedItemBuilder: (BuildContext context) {
75+
return _dropDownItems.map<Widget>((String item) {
76+
return Container(
77+
alignment: Alignment.center,
78+
child: Text(item),
79+
);
80+
}).toList();
81+
},
82+
items: _dropDownItems
83+
.map<DropdownMenuItem<String>>((String value) {
84+
return DropdownMenuItem<String>(
85+
value: value,
86+
child: Text(value),
87+
);
88+
}).toList(),
89+
),
90+
Spacer(),
91+
PopupMenuButton<Commands>(
92+
onSelected: (Commands result) {
93+
switch (result) {
94+
case Commands.heroAndScholar:
95+
setState(() {
96+
_heroAndScholar = !_heroAndScholar;
97+
});
98+
break;
99+
case Commands.hurricaneCame:
100+
// ...handle hurricane option
101+
102+
break;
103+
// ...other items handled here
104+
}
105+
},
106+
itemBuilder: (BuildContext context) =>
107+
<PopupMenuEntry<Commands>>[
108+
CheckedPopupMenuItem<Commands>(
109+
checked: _heroAndScholar,
110+
value: Commands.heroAndScholar,
111+
child: const Text('Hero and scholar'),
112+
),
113+
const PopupMenuDivider(),
114+
const PopupMenuItem<Commands>(
115+
value: Commands.hurricaneCame,
116+
child: ListTile(
117+
leading: Icon(null),
118+
title: Text('Bring hurricane'),
119+
),
120+
),
121+
],
122+
),
123+
MaterialButton(
124+
onPressed: () {
125+
print("first");
126+
//future
127+
getUserInfo().then((value) {
128+
print(value);
129+
}).catchError((e) {
130+
print(e);
131+
});
132+
133+
print("last");
134+
},
135+
child: Text("Click by future"),
136+
),
137+
MaterialButton(
138+
onPressed: () async {
139+
print("first");
140+
141+
//async await
142+
try {
143+
print(await getUserInfo());
144+
} catch (e) {
145+
print(e);
146+
} finally {
147+
print("finally");
148+
}
149+
150+
print("last");
151+
},
152+
child: Text("Click by async"),
153+
),
154+
Spacer(),
155+
Spacer(),
156+
Spacer(),
157+
],
158+
),
159+
Spacer(),
160+
],
161+
),
162+
);
163+
}
164+
165+
// Future<String> getLoginUser() async {
166+
// return await Future<String>.delayed(
167+
// Duration(seconds: 5),
168+
// () {
169+
// return "";
170+
// },
171+
// );
172+
// }
173+
174+
Future<String> getUserInfo() {
175+
return Future<String>.delayed(Duration(seconds: 5), () {
176+
return "delayed task";
177+
});
178+
}
179+
}

0 commit comments

Comments
 (0)