Skip to content

Commit 6c0c7ac

Browse files
authored
Merge pull request #39 from splashbyte/version0.8.0
version 0.8.0-beta.4
2 parents 75a00a5 + 73e36e9 commit 6c0c7ac

22 files changed

Lines changed: 1252 additions & 579 deletions

CHANGELOG.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
## 0.8.0-beta.4 (2023-08-18)
2+
3+
- BREAKING: removes `IconTheme` for controlling default size of `Icon`s
4+
- BREAKING: changes default background color from `ThemeData.scaffoldBackgroundColor` to `ThemeData.colorScheme.surface`
5+
- BREAKING: renames `dif` to `spacing` in all constructors
6+
17
## 0.8.0-beta.3 (2023-08-11)
28

39
- BREAKING: replaces `transitionType` with `indicatorTransition` in `AnimatedToggleSwitch.rolling()`,
410
`AnimatedToggleSwitch.rollingByHeight()` and `AnimatedToggleSwitch.dual()`
5-
- BREAKING: replaces `iconSize` and `selectedIconSize`
6-
- `rolling()`, `rollingByHeight()` and `dual()`: now uses IconTheme for controlling default size of Icons
11+
- BREAKING: replaces `iconSize` and `selectedIconSize` in `AnimatedToggleSwitch` constructors
12+
- `rolling()`, `rollingByHeight()`, `dual()`: now uses IconTheme for controlling default size of `Icon`s
713
- `size()`, `sizeByHeight()`: new parameter `selectedIconScale` controls scaling
814

915
## 0.8.0-beta.2 (2023-08-01)
@@ -22,11 +28,10 @@
2228
## 0.8.0-beta.0 (2023-07-29)
2329

2430
- adds tests for all `AnimatedToggleSwitch` constructors
25-
- adds `separatorBuilder`, `customSeparatorBuilder`, `style` and `styleAnimationType`
26-
to `AnimatedToggleSwitch`
31+
- adds `separatorBuilder`, `customSeparatorBuilder`, `style` and `styleAnimationType` to `AnimatedToggleSwitch`
2732
- adds `separatorBuilder` to `CustomAnimatedToggleSwitch`
2833
- fixes initial loading
29-
- BREAKING: moves many parameters to `style`:
34+
- BREAKING: moves many parameters in `AnimatedToggleSwitch` to `style`:
3035
- `innerColor` (renamed to `backgroundColor`)
3136
- `innerGradient` (renamed to `backgroundGradient`)
3237
- `borderColor`
@@ -38,15 +43,12 @@
3843
- `foregroundBoxShadow` (renamed to `indicatorBoxShadow`)
3944
- `boxShadow`
4045
- BREAKING: merges `borderColorBuilder` with `styleBuilder`
41-
- BREAKING: `indicatorAnimationType`
42-
handles `ToggleStyle.indicatorColor`, `ToggleStyle.indicatorBorderRadius`, `ToggleStyle.indicatorBorder`
43-
and `ToggleStyle.indicatorBoxShadow` now
46+
- BREAKING: `indicatorAnimationType` handles `ToggleStyle.indicatorColor`, `ToggleStyle.indicatorBorderRadius`, `ToggleStyle.indicatorBorder` and `ToggleStyle.indicatorBoxShadow` now
4447

4548
## 0.7.0 (2023-06-19)
4649

4750
- adds possibility that no valid value is selected (by setting `allowUnlistedValues` to `true`)
48-
- adds new parameters to almost all
49-
constructors: `allowUnlistedValues`, `indicatorAppearingBuilder`, `indicatorAppearingDuration`, `indicatorAppearingCurve`
51+
- adds new parameters to almost all constructors: `allowUnlistedValues`, `indicatorAppearingBuilder`, `indicatorAppearingDuration`, `indicatorAppearingCurve`
5052

5153
## 0.6.2 (2023-03-09)
5254

@@ -61,13 +63,10 @@
6163
- fixes README
6264
- fixes #28
6365
- BREAKING: Increases minimum SDK to 2.17
64-
- BREAKING: Renames `value` to `current` and `previousValue` to `previous`
65-
in `DetailedGlobalToggleProperties`
66-
- BREAKING Feature: Adds loading animation to all switches. You can disable it by setting `loading`
67-
to false.
66+
- BREAKING: Renames `value` to `current` and `previousValue` to `previous` in `DetailedGlobalToggleProperties`
67+
- BREAKING Feature: Adds loading animation to all switches. You can disable it by setting `loading` to false.
6868
- Adds `innerGradient` to `AnimatedToggleSwitch`
69-
- Adds `transitionType` to `AnimatedToggleSwitch.rolling`, `AnimatedToggleSwitch.rollingByHeight`
70-
and `AnimatedToggleSwitch.dual`
69+
- Adds `transitionType` to `AnimatedToggleSwitch.rolling`, `AnimatedToggleSwitch.rollingByHeight` and `AnimatedToggleSwitch.dual`
7170

7271
## 0.5.2 (2022-04-22)
7372

@@ -85,16 +84,14 @@
8584

8685
- Minor performance improvement
8786
- Fixes problems with tight constraints
88-
- BREAKING: Changes default values of `animationOffset` and `clipAnimation`
89-
in `AnimatedToggleSwitch.dual`
87+
- BREAKING: Changes default values of `animationOffset` and `clipAnimation` in `AnimatedToggleSwitch.dual`
9088

9189
## 0.4.0 (2022-04-03)
9290

9391
- Minor fixes and performance improvements
9492
- Adds `indicatorBorderRadius` to `AnimatedToggleSwitch`
9593
- Adds `animationOffset`, `clipAnimation` and `opacityAnimation` to `AnimatedToggleSwitch.dual`
96-
- BREAKING: Sets default values of `animationOffset`, `clipAnimation` and `opacityAnimation`
97-
in `AnimatedToggleSwitch.dual`
94+
- BREAKING: Sets default values of `animationOffset`, `clipAnimation` and `opacityAnimation` in `AnimatedToggleSwitch.dual`
9895
- BREAKING: Renames `foregroundBorder` to `indicatorBorder`
9996

10097
## 0.3.1 (2022-03-23)
@@ -104,12 +101,10 @@
104101
## 0.3.0 (2022-03-21)
105102

106103
- Introduces `CustomAnimatedToggleSwitch` for maximum customizability
107-
- Most constructors of `AnimatedToggleSwitch` have a standard and a more customizable parameter for
108-
their builders now
104+
- Most constructors of `AnimatedToggleSwitch` have a standard and a more customizable parameter for their builders now
109105
- Full support of `TextDirection.rtl`
110106
- Adds animation when dragging the switch
111-
- Adds `minTouchTargetSize`, `dragStartDuration`, `dragStartCurve` and `textDirection`
112-
to `AnimatedToggleSwitch`
107+
- Adds `minTouchTargetSize`, `dragStartDuration`, `dragStartCurve` and `textDirection` to `AnimatedToggleSwitch`
113108
- BREAKING: `TextDirection` is taken from `BuildContext` by default now!!!
114109
- BREAKING: Changes parameters and names of some builders
115110
- BREAKING: Renames `AnimatedToggleSwitch.byHeight` to `AnimatedToggleSwitch.customByHeight`

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
### If you like this package, please leave a like there on [pub.dev](https://pub.dev/packages/animated_toggle_switch) and star on [GitHub](https://github.com/SplashByte/animated_toggle_switch).
1414

15-
Fully customizable, draggable and animated switch with multiple choices and [smooth loading animation](#simple-rolling-animation-with-loading). It has prebuilt constructors for rolling and size animations, but it also allows you to create your own switches with `CustomAnimatedToggleSwitch`.
15+
Fully customizable, draggable and animated switch with multiple choices and [smooth loading animation](#loading-animation). It has prebuilt constructors for rolling and size animations, but it also allows you to create your own switches with `CustomAnimatedToggleSwitch`.
1616
`LTR` and `RTL` are both supported.
17-
[Switches without an (initial) selection](#simple-rolling-animation-with-nullable-selection) are also possible.
17+
[Switches without an (initial) selection](#nullable-selection) are also possible.
1818
Most builder arguments of `AnimatedToggleSwitch` have a standard and a custom version. This ensures that you can get started easily and still customize a lot if necessary.
1919

2020
For a slider with a similar look you can check out [action_slider](https://pub.dev/packages/action_slider).
@@ -91,7 +91,7 @@ AnimatedToggleSwitch<int>.rolling(
9191
)
9292
```
9393

94-
### Simple rolling animation with loading
94+
### Loading animation
9595
![animated_toggle_switch_example_rolling_loading](https://user-images.githubusercontent.com/43761463/209121057-2ff2bfc3-063e-4704-a981-f5cc5f54720a.gif)
9696
To use the loading animation, you simply have to return a `Future` in `onChanged` or `onTap`.
9797
You can alternatively control the loading manually with the `loading` parameter.
@@ -111,7 +111,7 @@ AnimatedToggleSwitch<int>.rolling(
111111
)
112112
```
113113

114-
### Simple rolling animation with nullable selection
114+
### Nullable selection
115115
![animated_toggle_switch_example_unlisted_value](https://github.com/splashbyte/animated_toggle_switch/assets/43761463/570f39e8-bc5c-4a19-a91a-d186d4bbd8fe)
116116
To use this feature, you simply have to set `allowUnlistedValues` to `true`.
117117

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ analyzer:
77

88
linter:
99
rules:
10-
prefer_single_quotes: true
10+
prefer_single_quotes: true
11+
parameter_assignments: true

example/lib/crazy_switch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class _CrazySwitchState extends State<CrazySwitch> {
2323

2424
return CustomAnimatedToggleSwitch(
2525
current: current,
26-
dif: 36.0,
26+
spacing: 36.0,
2727
values: [false, true],
2828
animationDuration: const Duration(milliseconds: 350),
2929
animationCurve: Curves.bounceOut,

example/lib/main.dart

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {
1414
Widget build(BuildContext context) {
1515
return MaterialApp(
1616
title: 'AnimatedToggleSwitch Demo',
17-
theme: ThemeData(),
17+
theme: ThemeData(scaffoldBackgroundColor: Colors.white),
1818
home: MyHomePage(title: 'Example'),
1919
);
2020
}
@@ -61,7 +61,7 @@ class _MyHomePageState extends State<MyHomePage> {
6161
current: positive,
6262
first: false,
6363
second: true,
64-
dif: 50.0,
64+
spacing: 50.0,
6565
style: const ToggleStyle(
6666
borderColor: Colors.transparent,
6767
boxShadow: const [
@@ -90,7 +90,7 @@ class _MyHomePageState extends State<MyHomePage> {
9090
current: positive,
9191
first: false,
9292
second: true,
93-
dif: 50.0,
93+
spacing: 50.0,
9494
style: const ToggleStyle(
9595
borderColor: Colors.transparent,
9696
boxShadow: const [
@@ -139,7 +139,7 @@ class _MyHomePageState extends State<MyHomePage> {
139139
current: positive,
140140
first: false,
141141
second: true,
142-
dif: 45.0,
142+
spacing: 45.0,
143143
animationDuration: const Duration(milliseconds: 600),
144144
style: ToggleStyle(
145145
borderColor: Colors.transparent,
@@ -192,7 +192,7 @@ class _MyHomePageState extends State<MyHomePage> {
192192
current: positive,
193193
first: false,
194194
second: true,
195-
dif: 45.0,
195+
spacing: 45.0,
196196
style: const ToggleStyle(
197197
borderColor: Colors.transparent,
198198
backgroundColor: Colors.black,
@@ -227,6 +227,45 @@ class _MyHomePageState extends State<MyHomePage> {
227227
),
228228
),
229229
),
230+
SizedBox(height: 16.0),
231+
AnimatedToggleSwitch<bool>.dual(
232+
current: positive,
233+
first: false,
234+
second: true,
235+
spacing: 45.0,
236+
animationCurve: Curves.easeInOut,
237+
animationDuration: const Duration(milliseconds: 600),
238+
style: ToggleStyle(
239+
borderColor: Colors.transparent,
240+
indicatorColor: Colors.white,
241+
backgroundColor: Colors.amber,
242+
),
243+
styleBuilder: (value) => ToggleStyle(
244+
backgroundColor: value ? Colors.orange : Colors.red[800]),
245+
borderWidth: 6.0,
246+
height: 60.0,
247+
loadingIconBuilder: (context, global) =>
248+
CupertinoActivityIndicator(
249+
color: Color.lerp(
250+
Colors.red[800], Colors.orange, global.position)),
251+
onChanged: (b) {
252+
setState(() => positive = b);
253+
return Future<dynamic>.delayed(Duration(seconds: 2));
254+
},
255+
iconBuilder: (value) => value
256+
? Icon(Icons.power_outlined,
257+
color: Colors.orange, size: 32.0)
258+
: Icon(Icons.power_settings_new_rounded,
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+
)),
268+
),
230269
Padding(
231270
padding: const EdgeInsets.all(8.0),
232271
child: Text(
@@ -245,7 +284,7 @@ class _MyHomePageState extends State<MyHomePage> {
245284
current: positive,
246285
first: false,
247286
second: true,
248-
dif: 45.0,
287+
spacing: 45.0,
249288
animationCurve: Curves.easeInOut,
250289
animationDuration: const Duration(milliseconds: 600),
251290
style: ToggleStyle(
@@ -402,7 +441,7 @@ class _MyHomePageState extends State<MyHomePage> {
402441
borderRadius: BorderRadius.circular(10.0),
403442
),
404443
height: 55,
405-
dif: 20.0,
444+
spacing: 20.0,
406445
loading: loading,
407446
),
408447
SizedBox(height: 16.0),
@@ -421,7 +460,7 @@ class _MyHomePageState extends State<MyHomePage> {
421460
borderColor: Colors.transparent,
422461
),
423462
height: 55,
424-
dif: 20.0,
463+
spacing: 20.0,
425464
loading: loading,
426465
),
427466
Padding(
@@ -434,7 +473,7 @@ class _MyHomePageState extends State<MyHomePage> {
434473
CustomAnimatedToggleSwitch<bool>(
435474
current: positive,
436475
values: [false, true],
437-
dif: 0.0,
476+
spacing: 0.0,
438477
indicatorSize: Size.square(30.0),
439478
animationDuration: const Duration(milliseconds: 200),
440479
animationCurve: Curves.linear,
@@ -545,6 +584,35 @@ class _MyHomePageState extends State<MyHomePage> {
545584
ToggleStyle(indicatorColor: colorBuilder(i)),
546585
onChanged: (i) => setState(() => value = i),
547586
),
587+
const SizedBox(height: 16.0),
588+
AnimatedToggleSwitch<bool>.size(
589+
current: positive,
590+
values: const [false, true],
591+
iconOpacity: 0.2,
592+
indicatorSize: const Size.fromWidth(100),
593+
customIconBuilder: (context, local, global) => Text(
594+
local.value ? 'RAM' : 'CPU',
595+
style: TextStyle(
596+
color: Color.lerp(
597+
Colors.black, Colors.white, local.animationValue))),
598+
borderWidth: 4.0,
599+
iconAnimationType: AnimationType.onHover,
600+
style: ToggleStyle(
601+
indicatorColor: Colors.teal,
602+
borderColor: Colors.transparent,
603+
borderRadius: BorderRadius.circular(10.0),
604+
boxShadow: [
605+
BoxShadow(
606+
color: Colors.black26,
607+
spreadRadius: 1,
608+
blurRadius: 2,
609+
offset: Offset(0, 1.5),
610+
),
611+
],
612+
),
613+
selectedIconScale: 1.0,
614+
onChanged: (b) => setState(() => positive = b),
615+
),
548616
Padding(
549617
padding: const EdgeInsets.all(8.0),
550618
child: Text(
@@ -567,7 +635,7 @@ class _MyHomePageState extends State<MyHomePage> {
567635
indicatorSize: const Size.fromWidth(100),
568636
iconAnimationType: AnimationType.onHover,
569637
styleAnimationType: AnimationType.onHover,
570-
dif: 2.0,
638+
spacing: 2.0,
571639
customSeparatorBuilder: (context, local, global) {
572640
final opacity =
573641
((global.position - local.position).abs() - 0.5)
@@ -642,7 +710,6 @@ class _MyHomePageState extends State<MyHomePage> {
642710
child: iconBuilder(pos.ceil()))
643711
]));
644712
},
645-
selectedIconScale: 1.0,
646713
iconBuilder: iconBuilder,
647714
style: const ToggleStyle(
648715
borderColor: Colors.red,

lib/src/foreground_indicator_transition.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class _RollingForegroundIndicatorTransition
2525
extends ForegroundIndicatorTransition {
2626
/// The radius which will be used for calculating the rotation.
2727
///
28-
/// If set to [null], a reasonable value is calculated from [indicatorSize] and [height].
28+
/// If set to [null], a reasonable value is calculated from [indicatorSize], [borderWidth] and [height].
2929
final double? rollingRadius;
3030

3131
const _RollingForegroundIndicatorTransition({this.rollingRadius}) : super._();

lib/src/properties.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class GlobalToggleProperties<T> {
1212
final T current;
1313

1414
/// The index of [current] in [values].
15+
///
16+
/// If [values] does not contain [current], this value is set to [-1].
1517
final int currentIndex;
1618

1719
/// The previous value of the switch.
@@ -57,7 +59,7 @@ class DetailedGlobalToggleProperties<T> extends GlobalToggleProperties<T> {
5759
/// The final width of the space between the icons.
5860
///
5961
/// May differ from the value passed to the switch.
60-
final double dif;
62+
final double spacing;
6163

6264
/// The final size of the indicator.
6365
///
@@ -67,10 +69,10 @@ class DetailedGlobalToggleProperties<T> extends GlobalToggleProperties<T> {
6769
/// The size of the switch exclusive the outer wrapper
6870
final Size switchSize;
6971

70-
Size get difSize => Size(dif, switchSize.height);
72+
Size get spacingSize => Size(spacing, switchSize.height);
7173

7274
const DetailedGlobalToggleProperties({
73-
required this.dif,
75+
required this.spacing,
7476
required this.indicatorSize,
7577
required this.switchSize,
7678
required super.position,
@@ -91,6 +93,8 @@ class LocalToggleProperties<T> {
9193
final T value;
9294

9395
/// The index of [value].
96+
///
97+
/// This value is [-1] if [values] does not contain [value].
9498
final int index;
9599

96100
const LocalToggleProperties({

0 commit comments

Comments
 (0)