File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class MyApp extends StatelessWidget {
26
26
),
27
27
ToggleSwitch (
28
28
initialLabelIndex: 0 ,
29
+ doubleTapDisable: true ,
29
30
totalSwitches: 3 ,
30
31
labels: ['America' , 'Canada' , 'Mexico' ],
31
32
onToggle: (index) {
@@ -113,8 +114,9 @@ class MyApp extends StatelessWidget {
113
114
ToggleSwitch (
114
115
minWidth: 90.0 ,
115
116
minHeight: 70.0 ,
116
- initialLabelIndex: 2 ,
117
+ initialLabelIndex: null ,
117
118
cornerRadius: 20.0 ,
119
+ doubleTapDisable: true ,
118
120
activeFgColor: Colors .white,
119
121
inactiveBgColor: Colors .grey,
120
122
inactiveFgColor: Colors .white,
Original file line number Diff line number Diff line change 3
3
import 'package:flutter/material.dart' ;
4
4
import 'package:flutter/rendering.dart' ;
5
5
6
- typedef OnToggle = void Function (int index);
6
+ typedef OnToggle = void Function (int ? index);
7
7
8
8
// ignore: must_be_immutable
9
9
class ToggleSwitch extends StatefulWidget {
@@ -337,15 +337,21 @@ class _ToggleSwitchState extends State<ToggleSwitch>
337
337
338
338
/// Handles selection
339
339
void _handleOnTap (int index) async {
340
+ bool notifyNull = false ;
340
341
if (widget.changeOnTap) {
341
342
if (widget.doubleTapDisable && widget.initialLabelIndex == index) {
342
343
setState (() => widget.initialLabelIndex = null );
344
+ notifyNull = true ;
343
345
} else {
344
346
setState (() => widget.initialLabelIndex = index);
345
347
}
346
348
}
347
349
if (widget.onToggle != null ) {
348
- widget.onToggle !(index);
350
+ if (notifyNull) {
351
+ widget.onToggle !(null );
352
+ } else {
353
+ widget.onToggle !(index);
354
+ }
349
355
}
350
356
}
351
357
You can’t perform that action at this time.
0 commit comments