Skip to content

Commit 430df5b

Browse files
committed
dart format
1 parent 6dca137 commit 430df5b

2 files changed

Lines changed: 83 additions & 117 deletions

File tree

example/lib/main.dart

Lines changed: 83 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@ class _MyHomePageState extends State<MyHomePage> {
7878
onChanged: (b) => setState(() => positive = b),
7979
styleBuilder: (b) =>
8080
ToggleStyle(indicatorColor: b ? Colors.red : Colors.green),
81-
iconBuilder: (value) =>
82-
value
81+
iconBuilder: (value) => value
8382
? Icon(Icons.coronavirus_rounded)
8483
: Icon(Icons.tag_faces_rounded),
85-
textBuilder: (value) =>
86-
value
84+
textBuilder: (value) => value
8785
? Center(child: Text('Oh no...'))
8886
: Center(child: Text('Nice :)')),
8987
),
@@ -107,32 +105,27 @@ class _MyHomePageState extends State<MyHomePage> {
107105
borderWidth: 5.0,
108106
height: 55,
109107
onChanged: (b) => setState(() => positive = b),
110-
styleBuilder: (b) =>
111-
ToggleStyle(
112-
backgroundColor: b ? Colors.white : Colors.black,
113-
indicatorColor: b ? Colors.blue : Colors.red,
114-
borderRadius: const BorderRadius.horizontal(
115-
left: Radius.circular(4.0),
116-
right: Radius.circular(50.0)),
117-
indicatorBorderRadius: BorderRadius.circular(
118-
b ? 50.0 : 4.0),
119-
),
120-
iconBuilder: (value) =>
121-
Icon(
122-
value
123-
? Icons.access_time_rounded
124-
: Icons.power_settings_new_rounded,
125-
size: 32.0,
126-
color: value ? Colors.black : Colors.white,
127-
),
128-
textBuilder: (value) =>
129-
value
108+
styleBuilder: (b) => ToggleStyle(
109+
backgroundColor: b ? Colors.white : Colors.black,
110+
indicatorColor: b ? Colors.blue : Colors.red,
111+
borderRadius: const BorderRadius.horizontal(
112+
left: Radius.circular(4.0), right: Radius.circular(50.0)),
113+
indicatorBorderRadius: BorderRadius.circular(b ? 50.0 : 4.0),
114+
),
115+
iconBuilder: (value) => Icon(
116+
value
117+
? Icons.access_time_rounded
118+
: Icons.power_settings_new_rounded,
119+
size: 32.0,
120+
color: value ? Colors.black : Colors.white,
121+
),
122+
textBuilder: (value) => value
130123
? const Center(
131-
child:
132-
Text('On', style: TextStyle(color: Colors.black)))
124+
child:
125+
Text('On', style: TextStyle(color: Colors.black)))
133126
: const Center(
134-
child:
135-
Text('Off', style: TextStyle(color: Colors.white))),
127+
child:
128+
Text('Off', style: TextStyle(color: Colors.white))),
136129
),
137130
SizedBox(height: 16.0),
138131
DefaultTextStyle.merge(
@@ -158,14 +151,14 @@ class _MyHomePageState extends State<MyHomePage> {
158151
return ToggleStyle(backgroundColor: Colors.red[800]);
159152
return ToggleStyle(
160153
backgroundGradient: LinearGradient(
161-
colors: [green, Colors.red[800]!],
162-
stops: [
163-
global.position -
164-
(1 - 2 * max(0, global.position - 0.5)) * 0.2,
165-
global.position +
166-
max(0, 2 * (global.position - 0.5)) * 0.2,
167-
],
168-
));
154+
colors: [green, Colors.red[800]!],
155+
stops: [
156+
global.position -
157+
(1 - 2 * max(0, global.position - 0.5)) * 0.2,
158+
global.position +
159+
max(0, 2 * (global.position - 0.5)) * 0.2,
160+
],
161+
));
169162
},
170163
borderWidth: 6.0,
171164
height: 60.0,
@@ -174,13 +167,11 @@ class _MyHomePageState extends State<MyHomePage> {
174167
color: Color.lerp(
175168
Colors.red[800], green, global.position)),
176169
onChanged: (b) => setState(() => positive = b),
177-
iconBuilder: (value) =>
178-
value
170+
iconBuilder: (value) => value
179171
? Icon(Icons.power_outlined, color: green, size: 32.0)
180172
: Icon(Icons.power_settings_new_rounded,
181-
color: Colors.red[800], size: 32.0),
182-
textBuilder: (value) =>
183-
value
173+
color: Colors.red[800], size: 32.0),
174+
textBuilder: (value) => value
184175
? Center(child: Text('Active'))
185176
: Center(child: Text('Inactive')),
186177
),
@@ -218,23 +209,20 @@ class _MyHomePageState extends State<MyHomePage> {
218209
borderWidth: 10.0,
219210
height: 50,
220211
loadingIconBuilder: (context, global) =>
221-
const CupertinoActivityIndicator(color: Colors.white),
212+
const CupertinoActivityIndicator(color: Colors.white),
222213
onChanged: (b) {
223214
setState(() => positive = b);
224215
return Future<dynamic>.delayed(Duration(seconds: 2));
225216
},
226-
styleBuilder: (b) =>
227-
ToggleStyle(
228-
indicatorColor: b ? Colors.purple : Colors.green),
229-
iconBuilder: (value) =>
230-
value
217+
styleBuilder: (b) => ToggleStyle(
218+
indicatorColor: b ? Colors.purple : Colors.green),
219+
iconBuilder: (value) => value
231220
? Icon(Icons.coronavirus_rounded)
232221
: Icon(Icons.tag_faces_rounded),
233-
textBuilder: (value) =>
234-
value
222+
textBuilder: (value) => value
235223
? Center(
236-
child: Text('Oh no...',
237-
style: const TextStyle(color: Colors.white)))
224+
child: Text('Oh no...',
225+
style: const TextStyle(color: Colors.white)))
238226
: Center(child: Text('Nice :)')),
239227
),
240228
),
@@ -252,10 +240,8 @@ class _MyHomePageState extends State<MyHomePage> {
252240
indicatorColor: Colors.white,
253241
backgroundColor: Colors.amber,
254242
),
255-
styleBuilder: (value) =>
256-
ToggleStyle(
257-
backgroundColor: value ? Colors.orange : Colors
258-
.red[800]),
243+
styleBuilder: (value) => ToggleStyle(
244+
backgroundColor: value ? Colors.orange : Colors.red[800]),
259245
borderWidth: 6.0,
260246
height: 60.0,
261247
loadingIconBuilder: (context, global) =>
@@ -266,21 +252,19 @@ class _MyHomePageState extends State<MyHomePage> {
266252
setState(() => positive = b);
267253
return Future<dynamic>.delayed(Duration(seconds: 2));
268254
},
269-
iconBuilder: (value) =>
270-
value
255+
iconBuilder: (value) => value
271256
? Icon(Icons.power_outlined,
272-
color: Colors.orange, size: 32.0)
257+
color: Colors.orange, size: 32.0)
273258
: Icon(Icons.power_settings_new_rounded,
274-
color: Colors.red[800], size: 32.0),
275-
textBuilder: (value) =>
276-
Center(
277-
child: Text(
278-
value ? 'Active' : 'Inactive',
279-
style: const TextStyle(
280-
color: Colors.white,
281-
fontSize: 20.0,
282-
fontWeight: FontWeight.w600),
283-
)),
259+
color: Colors.red[800], size: 32.0),
260+
textBuilder: (value) => Center(
261+
child: Text(
262+
value ? 'Active' : 'Inactive',
263+
style: const TextStyle(
264+
color: Colors.white,
265+
fontSize: 20.0,
266+
fontWeight: FontWeight.w600),
267+
)),
284268
),
285269
Padding(
286270
padding: const EdgeInsets.all(8.0),
@@ -308,9 +292,8 @@ class _MyHomePageState extends State<MyHomePage> {
308292
indicatorColor: Colors.white,
309293
backgroundColor: Colors.black,
310294
),
311-
styleBuilder: (value) =>
312-
ToggleStyle(
313-
backgroundColor: value ? green : Colors.red[800]),
295+
styleBuilder: (value) => ToggleStyle(
296+
backgroundColor: value ? green : Colors.red[800]),
314297
borderWidth: 6.0,
315298
height: 60.0,
316299
loadingIconBuilder: (context, global) =>
@@ -321,13 +304,11 @@ class _MyHomePageState extends State<MyHomePage> {
321304
setState(() => positive = b);
322305
return Future<dynamic>.delayed(Duration(seconds: 2));
323306
},
324-
iconBuilder: (value) =>
325-
value
307+
iconBuilder: (value) => value
326308
? Icon(Icons.power_outlined, color: green, size: 32.0)
327309
: Icon(Icons.power_settings_new_rounded,
328-
color: Colors.red[800], size: 32.0),
329-
textBuilder: (value) =>
330-
value
310+
color: Colors.red[800], size: 32.0),
311+
textBuilder: (value) => value
331312
? Center(child: Text('Active'))
332313
: Center(child: Text('Inactive')),
333314
),
@@ -376,10 +357,9 @@ class _MyHomePageState extends State<MyHomePage> {
376357
onChanged: (i) => setState(() => nullableValue = i),
377358
iconBuilder: rollingIconBuilder,
378359
customStyleBuilder: (context, local, global) {
379-
final color = local.isValueListed ? null : Theme
380-
.of(context)
381-
.colorScheme
382-
.error;
360+
final color = local.isValueListed
361+
? null
362+
: Theme.of(context).colorScheme.error;
383363
return ToggleStyle(borderColor: color, indicatorColor: color);
384364
},
385365
),
@@ -446,13 +426,11 @@ class _MyHomePageState extends State<MyHomePage> {
446426
iconBuilder: coloredRollingIconBuilder,
447427
borderWidth: 3.0,
448428
styleAnimationType: AnimationType.onHover,
449-
styleBuilder: (value) =>
450-
ToggleStyle(
451-
backgroundColor: colorBuilder(value),
452-
borderRadius: BorderRadius.circular(value * 10.0),
453-
indicatorBorderRadius: BorderRadius.circular(
454-
value * 10.0),
455-
),
429+
styleBuilder: (value) => ToggleStyle(
430+
backgroundColor: colorBuilder(value),
431+
borderRadius: BorderRadius.circular(value * 10.0),
432+
indicatorBorderRadius: BorderRadius.circular(value * 10.0),
433+
),
456434
),
457435
),
458436
SizedBox(height: 16.0),
@@ -486,7 +464,7 @@ class _MyHomePageState extends State<MyHomePage> {
486464
style: ToggleStyle(
487465
indicatorColor: Colors.white,
488466
backgroundGradient:
489-
const LinearGradient(colors: [Colors.red, Colors.blue]),
467+
const LinearGradient(colors: [Colors.red, Colors.blue]),
490468
borderColor: Colors.transparent,
491469
),
492470
height: 55,
@@ -529,7 +507,7 @@ class _MyHomePageState extends State<MyHomePage> {
529507
theme.colorScheme.background,
530508
global.position),
531509
borderRadius:
532-
const BorderRadius.all(Radius.circular(50.0)),
510+
const BorderRadius.all(Radius.circular(50.0)),
533511
),
534512
)),
535513
child,
@@ -570,10 +548,8 @@ class _MyHomePageState extends State<MyHomePage> {
570548
indicatorSize: const Size.fromWidth(100),
571549
iconAnimationType: AnimationType.onHover,
572550
styleAnimationType: AnimationType.onHover,
573-
iconBuilder: (value) =>
574-
Icon(
575-
value.isEven ? Icons.cancel : Icons
576-
.access_time_rounded),
551+
iconBuilder: (value) => Icon(
552+
value.isEven ? Icons.cancel : Icons.access_time_rounded),
577553
style: ToggleStyle(
578554
borderColor: Colors.transparent,
579555
),
@@ -622,13 +598,11 @@ class _MyHomePageState extends State<MyHomePage> {
622598
values: const [false, true],
623599
iconOpacity: 0.2,
624600
indicatorSize: const Size.fromWidth(100),
625-
customIconBuilder: (context, local, global) =>
626-
Text(
627-
local.value ? 'RAM' : 'CPU',
628-
style: TextStyle(
629-
color: Color.lerp(
630-
Colors.black, Colors.white,
631-
local.animationValue))),
601+
customIconBuilder: (context, local, global) => Text(
602+
local.value ? 'RAM' : 'CPU',
603+
style: TextStyle(
604+
color: Color.lerp(
605+
Colors.black, Colors.white, local.animationValue))),
632606
borderWidth: 4.0,
633607
iconAnimationType: AnimationType.onHover,
634608
style: ToggleStyle(
@@ -672,8 +646,8 @@ class _MyHomePageState extends State<MyHomePage> {
672646
spacing: 2.0,
673647
customSeparatorBuilder: (context, local, global) {
674648
final opacity =
675-
((global.position - local.position).abs() - 0.5)
676-
.clamp(0.0, 1.0);
649+
((global.position - local.position).abs() - 0.5)
650+
.clamp(0.0, 1.0);
677651
return VerticalDivider(
678652
indent: 10.0,
679653
endIndent: 10.0,
@@ -713,9 +687,8 @@ class _MyHomePageState extends State<MyHomePage> {
713687
);
714688
},
715689
style: ToggleStyle(borderColor: Colors.transparent),
716-
styleBuilder: (i) =>
717-
ToggleStyle(
718-
indicatorColor:
690+
styleBuilder: (i) => ToggleStyle(
691+
indicatorColor:
719692
i.isEven == true ? Colors.amber : Colors.red),
720693
onChanged: (i) => setState(() => value = i),
721694
),
@@ -751,9 +724,8 @@ class _MyHomePageState extends State<MyHomePage> {
751724
borderRadius: BorderRadius.all(Radius.circular(8.0)),
752725
indicatorBorderRadius: BorderRadius.zero,
753726
),
754-
styleBuilder: (i) =>
755-
ToggleStyle(
756-
indicatorColor:
727+
styleBuilder: (i) => ToggleStyle(
728+
indicatorColor:
757729
i.isEven == true ? Colors.green : Colors.tealAccent),
758730
onChanged: (i) => setState(() => value = i),
759731
),
@@ -782,19 +754,15 @@ class _MyHomePageState extends State<MyHomePage> {
782754
indicatorSize: const Size.square(1.5),
783755
style: ToggleStyle(borderRadius: BorderRadius.circular(75.0)),
784756
),
785-
SizedBox(height: MediaQuery
786-
.of(context)
787-
.padding
788-
.bottom + 16.0),
757+
SizedBox(height: MediaQuery.of(context).padding.bottom + 16.0),
789758
],
790759
),
791760
), // This trailing comma makes auto-formatting nicer for build methods.
792761
),
793762
);
794763
}
795764

796-
Color colorBuilder(int value) =>
797-
switch (value) {
765+
Color colorBuilder(int value) => switch (value) {
798766
0 => Colors.blueAccent,
799767
1 => Colors.green,
800768
2 => Colors.orangeAccent,
@@ -817,8 +785,7 @@ class _MyHomePageState extends State<MyHomePage> {
817785
return Icon(iconDataByValue(value));
818786
}
819787

820-
IconData iconDataByValue(int? value) =>
821-
switch (value) {
788+
IconData iconDataByValue(int? value) => switch (value) {
822789
0 => Icons.access_time_rounded,
823790
1 => Icons.check_circle_outline_rounded,
824791
2 => Icons.power_settings_new_rounded,

lib/src/properties.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class LocalToggleProperties<T> {
100100
/// If [values] does not contain [value], this value is set to [-1].
101101
final int index;
102102

103-
104103
/// This value indicates if [values] does contain [value].
105104
bool get isValueListed => index >= 0;
106105

0 commit comments

Comments
 (0)