Skip to content

Commit b07df52

Browse files
committed
revised active and inactive icons
1 parent 95b387a commit b07df52

File tree

6 files changed

+75
-21
lines changed

6 files changed

+75
-21
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.3.1] - April 12, 2021
2+
3+
* Revised the activeIcon and inactiveIcon to accept other types of widget including Images, Icon and FontAwesome Icons.
4+
15
## [0.3.0] - March 06, 2021
26

37
* Migrated to null safety. Beware for possible breaking changes.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Add this to your package's `pubspec.yaml` file:
2222

2323
```yaml
2424
dependencies:
25-
flutter_switch: ^0.3.0
25+
flutter_switch: ^0.3.1
2626
```
2727
2828
You can install packages from the command line with Flutter:

example/lib/main.dart

+44
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class _MyHomePageState extends State<MyHomePage> {
2828
bool status5 = false;
2929
bool status6 = false;
3030
bool status7 = false;
31+
bool status8 = false;
3132
bool isSwitchOn = false;
3233

3334
Color _textColor = Colors.black;
@@ -297,6 +298,49 @@ class _MyHomePageState extends State<MyHomePage> {
297298
),
298299
],
299300
),
301+
SizedBox(height: 20.0),
302+
Text("Image as toggle icon"),
303+
SizedBox(height: 10.0),
304+
Row(
305+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
306+
children: <Widget>[
307+
FlutterSwitch(
308+
width: 100.0,
309+
height: 55.0,
310+
toggleSize: 45.0,
311+
value: status8,
312+
borderRadius: 30.0,
313+
padding: 2.0,
314+
activeToggleColor: Color(0xFF0082C8),
315+
inactiveToggleColor: Color(0xFF01579B),
316+
activeSwitchBorder: Border.all(
317+
color: Color(0xFF00D2B8),
318+
width: 6.0,
319+
),
320+
inactiveSwitchBorder: Border.all(
321+
color: Color(0xFF29B6F6),
322+
width: 6.0,
323+
),
324+
activeColor: Color(0xFF55DDCA),
325+
inactiveColor: Color(0xFF54C5F8),
326+
activeIcon: Image.network(
327+
"https://img2.pngio.com/functional-bits-in-flutter-flutter-community-medium-flutter-png-1000_1000.png",
328+
),
329+
inactiveIcon: Image.network(
330+
"https://upload.wikimedia.org/wikipedia/commons/7/7e/Dart-logo.png",
331+
),
332+
onToggle: (val) {
333+
setState(() {
334+
status8 = val;
335+
});
336+
},
337+
),
338+
Container(
339+
alignment: Alignment.centerRight,
340+
child: Text("Value: $status8"),
341+
),
342+
],
343+
),
300344
],
301345
),
302346
),

example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ packages:
6868
path: ".."
6969
relative: true
7070
source: path
71-
version: "0.3.0"
71+
version: "0.3.1"
7272
flutter_test:
7373
dependency: "direct dev"
7474
description: flutter

lib/flutter_switch.dart

+24-18
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,16 @@ class FlutterSwitch extends StatefulWidget {
230230
final BoxBorder? inactiveToggleBorder;
231231

232232
/// The icon inside the toggle when the given value is true.
233+
/// activeIcon can be an Icon Widget, an Image or Fontawesome Icons.
233234
///
234235
/// This property is optional.
235-
final Icon? activeIcon;
236+
final Widget? activeIcon;
236237

237238
/// The icon inside the toggle when the given value is false.
239+
/// inactiveIcon can be an Icon Widget, an Image or Fontawesome Icons.
238240
///
239241
/// This property is optional.
240-
final Icon? inactiveIcon;
242+
final Widget? inactiveIcon;
241243

242244
/// The duration in milliseconds to change the state of the switch
243245
///
@@ -377,29 +379,33 @@ class _FlutterSwitchState extends State<FlutterSwitch>
377379
child: Container(
378380
width: widget.toggleSize,
379381
height: widget.toggleSize,
382+
padding: EdgeInsets.all(4.0),
380383
decoration: BoxDecoration(
381384
shape: BoxShape.circle,
382385
color: _toggleColor,
383386
border: _toggleBorder,
384387
),
385-
child: Container(
386-
child: Stack(
387-
children: [
388-
Center(
389-
child: AnimatedOpacity(
390-
opacity: widget.value ? 1.0 : 0.0,
391-
duration: widget.duration,
392-
child: widget.activeIcon,
388+
child: FittedBox(
389+
fit: BoxFit.contain,
390+
child: Container(
391+
child: Stack(
392+
children: [
393+
Center(
394+
child: AnimatedOpacity(
395+
opacity: widget.value ? 1.0 : 0.0,
396+
duration: widget.duration,
397+
child: widget.activeIcon,
398+
),
393399
),
394-
),
395-
Center(
396-
child: AnimatedOpacity(
397-
opacity: !widget.value ? 1.0 : 0.0,
398-
duration: widget.duration,
399-
child: widget.inactiveIcon,
400+
Center(
401+
child: AnimatedOpacity(
402+
opacity: !widget.value ? 1.0 : 0.0,
403+
duration: widget.duration,
404+
child: widget.inactiveIcon,
405+
),
400406
),
401-
),
402-
],
407+
],
408+
),
403409
),
404410
),
405411
),

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_switch
22
description: A custom switch widget that can have a custom height and width, borders, border radius, colors, toggle size, custom text and icons inside the toggle.
3-
version: 0.3.0
3+
version: 0.3.1
44
homepage: https://github.com/boringdeveloper/FlutterSwitch
55

66
environment:

0 commit comments

Comments
 (0)