Skip to content

Commit

Permalink
version 0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
maeddin committed Dec 18, 2024
1 parent c50b8ad commit 8d2f16f
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 53 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish to pub.dev

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:
publish:
permissions:
id-token: write
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: pub.dev
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.4 (2024-12-18)

- adds possibility to add `ToggleStyle` to `ThemeData` as `ThemeExtension`
- removes usage of deprecated members

## 0.8.3 (2024-08-12)

- adds support for vertical switches ([#61](https://github.com/splashbyte/animated_toggle_switch/issues/61))
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ AnimatedToggleSwitch<int>.rolling(
```

### Styling
#### Styling with constructor
`style`, `styleBuilder`, `customStyleBuilder` and `styleList` can be used to style an `AnimatedToggleSwitch`.
For the general look of the switch, you can use `style`.
For parameters that should change with the selection, you can use `styleBuilder` or `styleList`.
Expand All @@ -94,6 +95,26 @@ AnimatedToggleSwitch<int>.rolling(
)
```

#### Styling with Theme
You can also add `ToggleStyle` to `ThemeData`.
This overwrites the default `ToggleStyle` values in all `AnimatedToggleSwitch` widgets in your `MaterialApp`.

```dart
MaterialApp(
theme: ThemeData(..., extensions: [ToggleStyle(...)]),
...
)
```

After that, you can access this `ToggleStyle` anywhere in your `MaterialApp`:

```dart
import 'package:animated_toggle_switch/animated_toggle_switch.dart';
...
Theme.of(context).toggleStyle
```

### Loading animation
![animated_toggle_switch_example_rolling_loading](https://user-images.githubusercontent.com/43761463/209121057-2ff2bfc3-063e-4704-a981-f5cc5f54720a.gif)
To use the loading animation, you simply have to return a `Future` in `onChanged` or `onTap`.
Expand Down Expand Up @@ -134,7 +155,7 @@ AnimatedToggleSwitch<int?>.rolling(
You can get a vertical version of any switch by calling `vertical()` on it.

```dart
AnimatedToggleSwitch<int?>.rolling(...).vertical()
AnimatedToggleSwitch<int>.rolling(...).vertical()
```

### Fully customizable toggle switch with `CustomAnimatedToggleSwitch`
Expand Down
2 changes: 1 addition & 1 deletion example/lib/crazy_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _CrazySwitchState extends State<CrazySwitch> {
borderRadius: BorderRadius.circular(50.0),
boxShadow: [
BoxShadow(
color: color.withOpacity(0.7),
color: color.withValues(alpha: 0.7),
blurRadius: 12.0,
offset: const Offset(0.0, 8.0),
),
Expand Down
3 changes: 2 additions & 1 deletion example/lib/load_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class _LoadSwitchState extends State<LoadSwitch> {
padding: const EdgeInsets.all(borderWidth / 2),
child: CircularProgressIndicator(
strokeWidth: borderWidth,
color: Colors.blue.withOpacity(global.loadingAnimationValue),
color:
Colors.blue.withValues(alpha: global.loadingAnimationValue),
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class _MyHomePageState extends State<MyHomePage> {
return VerticalDivider(
indent: 10.0,
endIndent: 10.0,
color: Colors.white38.withOpacity(opacity));
color: Colors.white38.withValues(alpha: opacity));
},
customIconBuilder: (context, local, global) {
final text = const ['not', 'only', 'icons'][local.index];
Expand Down Expand Up @@ -676,7 +676,7 @@ class _MyHomePageState extends State<MyHomePage> {
styleBuilder: (i) {
final color = colorBuilder(i);
return ToggleStyle(
backgroundColor: color.withOpacity(0.3),
backgroundColor: color.withValues(alpha: 0.3),
indicatorColor: color,
);
},
Expand Down
32 changes: 16 additions & 16 deletions 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.8.3"
version: "0.8.4"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -44,10 +44,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -75,18 +75,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.7"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.8"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -139,7 +139,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand All @@ -152,10 +152,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.12.0"
stream_channel:
dependency: transitive
description:
Expand All @@ -168,10 +168,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -184,10 +184,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.3"
url_launcher:
dependency: "direct main"
description:
Expand Down Expand Up @@ -264,10 +264,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.3.0"
web:
dependency: transitive
description:
Expand Down
8 changes: 4 additions & 4 deletions lib/animated_toggle_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

part 'src/animations.dart';
part 'src/cursors.dart';
part 'src/foreground_indicator_transition.dart';
part 'src/properties.dart';
part 'src/style.dart';
part 'src/tweens.dart';
part 'src/cursors.dart';
part 'src/widgets/animation_type_builder.dart';
part 'src/foreground_indicator_transition.dart';
part 'src/widgets/animated_toggle_switch.dart';
part 'src/widgets/animation_type_builder.dart';
part 'src/widgets/conditional_wrapper.dart';
part 'src/widgets/custom_animated_toggle_switch.dart';
part 'src/widgets/hover_region.dart';
part 'src/widgets/conditional_wrapper.dart';
113 changes: 109 additions & 4 deletions lib/src/style.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of 'package:animated_toggle_switch/animated_toggle_switch.dart';

/// The base class for all toggle styles.
abstract class _BaseToggleStyle {
abstract class _BaseToggleStyle extends ThemeExtension<_BaseToggleStyle> {
const _BaseToggleStyle._();

ToggleStyleProperty<Color>? get _indicatorColor;
Expand Down Expand Up @@ -56,6 +56,10 @@ abstract class _BaseToggleStyle {
AnimationType animationType) =>
(style1, style2, t) => _lerp(style1, style2, t, animationType);

@override
_BaseToggleStyle lerp(_BaseToggleStyle other, double t) =>
_lerp(this, other, t, AnimationType.none);

static _BaseToggleStyle _lerp(_BaseToggleStyle style1,
_BaseToggleStyle style2, double t, AnimationType animationType) =>
_CustomToggleStyle._(
Expand Down Expand Up @@ -116,6 +120,9 @@ abstract class _BaseToggleStyle {

/// Currently not supported.
class _CustomToggleStyle extends _BaseToggleStyle {
@override
Object get type => _CustomToggleStyle;

@override
final ToggleStyleProperty<Color>? _indicatorColor;
@override
Expand Down Expand Up @@ -186,9 +193,61 @@ class _CustomToggleStyle extends _BaseToggleStyle {
_indicatorBoxShadow = indicatorBoxShadow,
_boxShadow = boxShadow,
super._();

ToggleStyleProperty<Color>? get indicatorColor => _indicatorColor;

ToggleStyleProperty<Gradient>? get indicatorGradient => _indicatorGradient;

ToggleStyleProperty<Color>? get backgroundColor => _backgroundColor;

ToggleStyleProperty<Gradient>? get backgroundGradient => _backgroundGradient;

ToggleStyleProperty<Color>? get borderColor => _borderColor;

ToggleStyleProperty<BorderRadiusGeometry>? get borderRadius => _borderRadius;

ToggleStyleProperty<BorderRadiusGeometry>? get indicatorBorderRadius =>
_indicatorBorderRadius;

ToggleStyleProperty<BoxBorder>? get indicatorBorder => _indicatorBorder;

ToggleStyleProperty<List<BoxShadow>>? get indicatorBoxShadow =>
_indicatorBoxShadow;

ToggleStyleProperty<List<BoxShadow>>? get boxShadow => _boxShadow;

@override
_CustomToggleStyle copyWith({
ToggleStyleProperty<Color>? indicatorColor,
ToggleStyleProperty<Gradient>? indicatorGradient,
ToggleStyleProperty<Color>? backgroundColor,
ToggleStyleProperty<Gradient>? backgroundGradient,
ToggleStyleProperty<Color>? borderColor,
ToggleStyleProperty<BorderRadiusGeometry>? borderRadius,
ToggleStyleProperty<BorderRadiusGeometry>? indicatorBorderRadius,
ToggleStyleProperty<BoxBorder>? indicatorBorder,
ToggleStyleProperty<List<BoxShadow>>? indicatorBoxShadow,
ToggleStyleProperty<List<BoxShadow>>? boxShadow,
}) =>
_CustomToggleStyle._(
indicatorColor: indicatorColor ?? this.indicatorColor,
indicatorGradient: indicatorGradient ?? this.indicatorGradient,
backgroundColor: backgroundColor ?? this.backgroundColor,
backgroundGradient: backgroundGradient ?? this.backgroundGradient,
borderColor: borderColor ?? this.borderColor,
borderRadius: borderRadius ?? this.borderRadius,
indicatorBorderRadius:
indicatorBorderRadius ?? this.indicatorBorderRadius,
indicatorBorder: indicatorBorder ?? this.indicatorBorder,
indicatorBoxShadow: indicatorBoxShadow ?? this.indicatorBoxShadow,
boxShadow: boxShadow ?? this.boxShadow,
);
}

class ToggleStyle extends _BaseToggleStyle {
@override
Object get type => ToggleStyle;

/// Background color of the indicator.
///
/// Defaults to [ThemeData.colorScheme.secondary].
Expand Down Expand Up @@ -230,9 +289,6 @@ class ToggleStyle extends _BaseToggleStyle {
final List<BoxShadow>? boxShadow;

/// Default constructor for [ToggleStyle].
///
/// If you want to disable the animation of single properties,
/// you can use [_CustomToggleStyle] for this purpose.
const ToggleStyle({
this.indicatorColor,
this.indicatorGradient,
Expand Down Expand Up @@ -330,6 +386,50 @@ class ToggleStyle extends _BaseToggleStyle {
indicatorBoxShadow.hashCode ^
boxShadow.hashCode;

@override
ToggleStyle copyWith({
Color? indicatorColor,
Gradient? indicatorGradient,
Color? backgroundColor,
Gradient? backgroundGradient,
Color? borderColor,
BorderRadiusGeometry? borderRadius,
BorderRadiusGeometry? indicatorBorderRadius,
BoxBorder? indicatorBorder,
List<BoxShadow>? indicatorBoxShadow,
List<BoxShadow>? boxShadow,
}) =>
ToggleStyle._(
indicatorColor: indicatorColor ?? this.indicatorColor,
indicatorGradient: indicatorGradient ?? this.indicatorGradient,
backgroundColor: backgroundColor ?? this.backgroundColor,
backgroundGradient: backgroundGradient ?? this.backgroundGradient,
borderColor: borderColor ?? this.borderColor,
borderRadius: borderRadius ?? this.borderRadius,
indicatorBorderRadius:
indicatorBorderRadius ?? this.indicatorBorderRadius,
indicatorBorder: indicatorBorder ?? this.indicatorBorder,
indicatorBoxShadow: indicatorBoxShadow ?? this.indicatorBoxShadow,
boxShadow: boxShadow ?? this.boxShadow,
);

@override
ToggleStyle lerp(ToggleStyle other, double t) {
final result = super.lerp(other, t);
return ToggleStyle._(
indicatorColor: result._indicatorColor?.value,
indicatorGradient: result._indicatorGradient?.value,
backgroundColor: result._backgroundColor?.value,
backgroundGradient: result._backgroundGradient?.value,
borderColor: result._borderColor?.value,
borderRadius: result._borderRadius?.value,
indicatorBorderRadius: result._indicatorBorderRadius?.value,
indicatorBorder: result._indicatorBorder?.value,
indicatorBoxShadow: result._indicatorBoxShadow?.value,
boxShadow: result._boxShadow?.value,
);
}

// coverage:ignore-end
}

Expand Down Expand Up @@ -375,3 +475,8 @@ class ToggleStyleProperty<T> {
);
}
}

extension XThemeDataToggleStyle on ThemeData {
ToggleStyle get toggleStyle =>
extension<ToggleStyle>() ?? const ToggleStyle();
}
Loading

0 comments on commit 8d2f16f

Please sign in to comment.