Skip to content

Commit

Permalink
version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maeddin committed Apr 20, 2022
1 parent 9f80fb2 commit bb5e407
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.0 (2022-04-20)

- Minor performance improvement
- Fixes problems with tight constraints (#20)
- BREAKING: Changes default values of `animationOffset` and `clipAnimation` in `AnimatedToggleSwitch.dual`

## 0.4.0 (2022-04-03)

- Minor fixes and performance improvements
Expand Down
68 changes: 33 additions & 35 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,39 @@ class _MyHomePageState extends State<MyHomePage> {
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'AnimatedToggleSwitch.dual:',
textAlign: TextAlign.center,
),
),
AnimatedToggleSwitch<bool>.dual(
current: positive,
first: false,
second: true,
dif: 50.0,
borderColor: Colors.transparent,
borderWidth: 5.0,
height: 55,
boxShadow: const [
BoxShadow(
color: Colors.black26,
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, 1.5),
),
],
onChanged: (b) => setState(() => positive = b),
colorBuilder: (b) => b ? Colors.red : Colors.green,
iconBuilder: (value) => value
? Icon(Icons.coronavirus_rounded)
: Icon(Icons.tag_faces_rounded),
textBuilder: (value) => value
? Center(child: Text('Oh no...'))
: Center(child: Text('Nice :)')),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
Expand Down Expand Up @@ -105,40 +137,6 @@ class _MyHomePageState extends State<MyHomePage> {
dif: 20.0,
borderColor: Colors.transparent,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'AnimatedToggleSwitch.dual:',
textAlign: TextAlign.center,
),
),
AnimatedToggleSwitch<bool>.dual(
current: positive,
first: false,
second: true,
dif: 50.0,
borderColor: Colors.transparent,
borderWidth: 5.0,
height: 55,
animationOffset: const Offset(20.0, 0),
clipAnimation: true,
boxShadow: const [
BoxShadow(
color: Colors.black26,
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, 1.5),
),
],
onChanged: (b) => setState(() => positive = b),
colorBuilder: (b) => b ? Colors.red : Colors.green,
iconBuilder: (value) => value
? Icon(Icons.coronavirus_rounded)
: Icon(Icons.tag_faces_rounded),
textBuilder: (value) => value
? Center(child: Text('Oh no...'))
: Center(child: Text('Nice :)')),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.1"
version: "0.5.0"
async:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/widgets/animated_toggle_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ class AnimatedToggleSwitch<T> extends StatelessWidget {
this.textDirection,
this.indicatorBorderRadius,
EdgeInsetsGeometry textMargin = const EdgeInsets.symmetric(horizontal: 8.0),
Offset animationOffset = Offset.zero,
bool clipAnimation = false,
Offset animationOffset = const Offset(20.0, 0),
bool clipAnimation = true,
bool opacityAnimation = true,
}) : assert(clipAnimation || opacityAnimation),
this.iconOpacity = 1.0,
Expand Down
16 changes: 9 additions & 7 deletions lib/src/widgets/custom_animated_toggle_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class _CustomAnimatedToggleSwitchState<T>
? width / widget.values.length
: factor * indicatorSize.width,
indicatorSize.height);
} else if (constraints.minWidth > width) {
dif += (constraints.minWidth - width) /
(widget.values.length - 1);
width = constraints.minWidth;
}

double dragDif =
Expand Down Expand Up @@ -470,14 +474,12 @@ class _Indicator extends StatelessWidget {
return Positioned.directional(
textDirection: textDirection,
top: (height - indicatorSize.height) / 2,
start: position - (indicatorSize.width + dragDif) / 2,
width: indicatorSize.width + dragDif,
start: position - indicatorSize.width / 2,
width: indicatorSize.width,
height: indicatorSize.height,
child: Center(
child: SizedBox(
width: indicatorSize.width,
child: child,
),
child: SizedBox(
width: indicatorSize.width,
child: child,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: animated_toggle_switch
description: Simple and animated toggle switch for multiple choices. It's a good alternative if you don't want to use something like a dropdown menu.
version: 0.4.0
version: 0.5.0
repository: https://github.com/SplashByte/animated_toggle_switch

environment:
Expand Down

0 comments on commit bb5e407

Please sign in to comment.