Skip to content

Commit

Permalink
Merge pull request #35 from splashbyte/version0.8.0
Browse files Browse the repository at this point in the history
0.8.0-beta.1
  • Loading branch information
maeddin committed Jul 31, 2023
2 parents 84f04d4 + cd8ad70 commit 6dc4799
Show file tree
Hide file tree
Showing 20 changed files with 687 additions and 356 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ build/
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3

# Coverage
coverage/
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 0.8.0-beta.0
## 0.8.0-beta.1 (2023-07-31)
- adds `active` to all constructors
- closes [#30](https://github.com/splashbyte/animated_toggle_switch/issues/30)
- minor improvements
- BREAKING: changes `separatorBuilder` parameters
- BREAKING: moves all cursor parameters to `cursors`

## 0.8.0-beta.0 (2023-07-29)
- adds tests for all `AnimatedToggleSwitch` constructors
- adds `separatorBuilder`, `customSeparatorBuilder`, `style` and `styleAnimationType` to `AnimatedToggleSwitch`
- adds `separatorBuilder` to `CustomAnimatedToggleSwitch`
Expand Down
9 changes: 9 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true
strict-raw-types: true

linter:
rules:
16 changes: 9 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class _MyHomePageState extends State<MyHomePage> {
const CupertinoActivityIndicator(color: Colors.white),
onChanged: (b) {
setState(() => positive = b);
return Future.delayed(Duration(seconds: 2));
return Future<dynamic>.delayed(Duration(seconds: 2));
},
styleBuilder: (b) => ToggleStyle(
indicatorColor: b ? Colors.purple : Colors.green),
Expand Down Expand Up @@ -206,7 +206,7 @@ class _MyHomePageState extends State<MyHomePage> {
Colors.red[800], green, global.position)),
onChanged: (b) {
setState(() => positive = b);
return Future.delayed(Duration(seconds: 2));
return Future<dynamic>.delayed(Duration(seconds: 2));
},
iconBuilder: (value) => value
? Icon(Icons.power_outlined, color: green, size: 32.0)
Expand Down Expand Up @@ -280,7 +280,7 @@ class _MyHomePageState extends State<MyHomePage> {
values: const [0, 1, 2, 3],
onChanged: (i) {
setState(() => value = i);
return Future.delayed(Duration(seconds: 3));
return Future<dynamic>.delayed(Duration(seconds: 3));
},
iconBuilder: rollingIconBuilder,
),
Expand All @@ -307,14 +307,15 @@ class _MyHomePageState extends State<MyHomePage> {
),
SizedBox(height: 16.0),
AnimatedToggleSwitch<int>.rolling(
active: false,
current: value,
values: const [0, 1, 2, 3],
onChanged: (i) {
setState(() {
value = i;
loading = true;
});
return Future.delayed(Duration(seconds: 3))
return Future<Object?>.delayed(Duration(seconds: 3))
.then((_) => setState(() => loading = false));
},
iconBuilder: rollingIconBuilder,
Expand Down Expand Up @@ -374,7 +375,8 @@ class _MyHomePageState extends State<MyHomePage> {
values: const [0, 1, 2, 3],
onChanged: (i) => setState(() => value = i),
iconBuilder: rollingIconBuilder,
separatorBuilder: (context, index) => const VerticalDivider(),
separatorBuilder: (index) =>
SizedBox.expand(child: ColoredBox(color: Colors.red)),
borderWidth: 4.5,
style: ToggleStyle(
indicatorColor: Colors.white,
Expand Down Expand Up @@ -423,7 +425,7 @@ class _MyHomePageState extends State<MyHomePage> {
iconBuilder: (context, local, global) {
return const SizedBox();
},
defaultCursor: SystemMouseCursors.click,
cursors: ToggleCursors(defaultCursor: SystemMouseCursors.click),
onTap: () => setState(() => positive = !positive),
iconsTappable: false,
wrapperBuilder: (context, global, child) {
Expand Down Expand Up @@ -497,7 +499,7 @@ class _MyHomePageState extends State<MyHomePage> {
i.isEven == true ? Colors.amber : Colors.red),
onChanged: (i) {
setState(() => value = i);
return Future.delayed(Duration(seconds: 3));
return Future<dynamic>.delayed(Duration(seconds: 3));
},
),
SizedBox(height: 16.0),
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.8.0"
version: "0.8.0-beta.1"
async:
dependency: transitive
description:
Expand Down
4 changes: 4 additions & 0 deletions lib/animated_toggle_switch.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library animated_toggle_switch;

import 'dart:async';
import 'dart:math';

import 'package:flutter/cupertino.dart';
Expand All @@ -8,6 +9,9 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

part 'src/properties.dart';
part 'src/style.dart';
part 'src/cursors.dart';
part 'src/widgets/animated_toggle_switch.dart';
part 'src/widgets/custom_animated_toggle_switch.dart';
part 'src/widgets/drag_region.dart';
part 'src/widgets/conditional_wrapper.dart';
56 changes: 56 additions & 0 deletions lib/src/cursors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// coverage:ignore-file
part of 'package:animated_toggle_switch/animated_toggle_switch.dart';

class ToggleCursors {
/// [MouseCursor] to show when not hovering an indicator.
///
/// Defaults to [SystemMouseCursors.click] if [iconsTappable] is [true]
/// and to [MouseCursor.defer] otherwise.
final MouseCursor? defaultCursor;

/// [MouseCursor] to show when grabbing the indicators.
final MouseCursor draggingCursor;

/// [MouseCursor] to show when hovering the indicators.
final MouseCursor dragCursor;

/// [MouseCursor] to show during loading.
final MouseCursor loadingCursor;

/// [MouseCursor] to show when [active] is set to [false].
final MouseCursor inactiveCursor;

const ToggleCursors({
this.defaultCursor,
this.draggingCursor = SystemMouseCursors.grabbing,
this.dragCursor = SystemMouseCursors.grab,
this.loadingCursor = MouseCursor.defer,
this.inactiveCursor = SystemMouseCursors.forbidden,
});

const ToggleCursors.all(MouseCursor cursor)
: defaultCursor = cursor,
draggingCursor = cursor,
dragCursor = cursor,
loadingCursor = cursor,
inactiveCursor = cursor;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ToggleCursors &&
runtimeType == other.runtimeType &&
defaultCursor == other.defaultCursor &&
draggingCursor == other.draggingCursor &&
dragCursor == other.dragCursor &&
loadingCursor == other.loadingCursor &&
inactiveCursor == other.inactiveCursor;

@override
int get hashCode =>
defaultCursor.hashCode ^
draggingCursor.hashCode ^
dragCursor.hashCode ^
loadingCursor.hashCode ^
inactiveCursor.hashCode;
}
8 changes: 6 additions & 2 deletions lib/src/properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GlobalToggleProperties<T> {
/// [0] means 'not loading' and [1] means 'loading'.
final double loadingAnimationValue;

final bool active;

const GlobalToggleProperties({
required this.position,
required this.current,
Expand All @@ -43,6 +45,7 @@ class GlobalToggleProperties<T> {
required this.textDirection,
required this.mode,
required this.loadingAnimationValue,
required this.active,
});
}

Expand Down Expand Up @@ -74,6 +77,7 @@ class DetailedGlobalToggleProperties<T> extends GlobalToggleProperties<T> {
required super.textDirection,
required super.mode,
required super.loadingAnimationValue,
required super.active,
});
}

Expand Down Expand Up @@ -177,7 +181,7 @@ class SizeProperties<T> extends AnimatedToggleProperties<T> {
});
}

class DifProperties<T> {
class SeparatorProperties<T> {
/// Index of the separator.
///
/// The separator is located between the items at [index] and [index+1].
Expand All @@ -186,7 +190,7 @@ class DifProperties<T> {
/// The position of the separator relative to the indices of the values.
double get position => index + 0.5;

const DifProperties({
const SeparatorProperties({
required this.index,
});
}
148 changes: 148 additions & 0 deletions lib/src/style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
part of 'package:animated_toggle_switch/animated_toggle_switch.dart';

class ToggleStyle {
/// Background color of the indicator.
final Color? indicatorColor;

/// Background color of the switch.
final Color? backgroundColor;

/// Gradient of the background. Overwrites [innerColor] if not [null].
final Gradient? backgroundGradient;

/// Border color of the switch.
///
/// For deactivating please set this to [Colors.transparent].
final Color? borderColor;

/// [BorderRadius] of the switch.
final BorderRadiusGeometry? borderRadius;

/// [BorderRadius] of the indicator.
///
/// Defaults to [borderRadius].
final BorderRadiusGeometry? indicatorBorderRadius;

/// [BorderRadius] of the indicator.
final BoxBorder? indicatorBorder;

/// Shadow for the indicator [Container].
final List<BoxShadow>? indicatorBoxShadow;

/// Shadow for the [Container] in the background.
final List<BoxShadow>? boxShadow;

/// Default constructor for [ToggleStyle].
const ToggleStyle({
this.indicatorColor,
this.backgroundColor,
this.backgroundGradient,
this.borderColor,
this.borderRadius,
this.indicatorBorderRadius,
this.indicatorBorder,
this.indicatorBoxShadow,
this.boxShadow,
});

/// Private constructor for setting all possible parameters.
ToggleStyle._({
required this.indicatorColor,
required this.backgroundColor,
required this.backgroundGradient,
required this.borderColor,
required this.borderRadius,
required this.indicatorBorderRadius,
required this.indicatorBorder,
required this.indicatorBoxShadow,
required this.boxShadow,
});

ToggleStyle _merge(ToggleStyle? other) => other == null
? this
: ToggleStyle._(
indicatorColor: other.indicatorColor ?? indicatorColor,
backgroundColor: other.backgroundColor ?? backgroundColor,
backgroundGradient: other.backgroundGradient ??
(other.backgroundColor == null ? null : backgroundGradient),
borderColor: other.borderColor ?? borderColor,
borderRadius: other.borderRadius ?? borderRadius,
indicatorBorderRadius: other.indicatorBorderRadius ??
other.borderRadius ??
indicatorBorderRadius ??
borderRadius,
indicatorBorder: other.indicatorBorder ?? indicatorBorder,
indicatorBoxShadow: other.indicatorBoxShadow ?? indicatorBoxShadow,
boxShadow: other.boxShadow ?? boxShadow,
);

static ToggleStyle _lerp(ToggleStyle style1, ToggleStyle style2, double t) =>
ToggleStyle._(
indicatorColor:
Color.lerp(style1.indicatorColor, style2.indicatorColor, t),
backgroundColor:
Color.lerp(style1.backgroundColor, style2.backgroundColor, t),
backgroundGradient: Gradient.lerp(
style1.backgroundGradient ?? style1.backgroundColor?.toGradient(),
style2.backgroundGradient ?? style2.backgroundColor?.toGradient(),
t,
),
borderColor: Color.lerp(style1.borderColor, style2.borderColor, t),
borderRadius: BorderRadiusGeometry.lerp(
style1.borderRadius,
style2.borderRadius,
t,
),
indicatorBorderRadius: BorderRadiusGeometry.lerp(
style1.indicatorBorderRadius ?? style1.borderRadius,
style2.indicatorBorderRadius ?? style2.borderRadius,
t,
),
indicatorBorder: BoxBorder.lerp(
style1.indicatorBorder,
style2.indicatorBorder,
t,
),
indicatorBoxShadow: BoxShadow.lerpList(
style1.indicatorBoxShadow,
style2.indicatorBoxShadow,
t,
),
boxShadow: BoxShadow.lerpList(
style1.boxShadow,
style2.boxShadow,
t,
),
);

// coverage:ignore-start

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ToggleStyle &&
runtimeType == other.runtimeType &&
indicatorColor == other.indicatorColor &&
backgroundColor == other.backgroundColor &&
backgroundGradient == other.backgroundGradient &&
borderColor == other.borderColor &&
borderRadius == other.borderRadius &&
indicatorBorderRadius == other.indicatorBorderRadius &&
indicatorBorder == other.indicatorBorder &&
indicatorBoxShadow == other.indicatorBoxShadow &&
boxShadow == other.boxShadow;

@override
int get hashCode =>
indicatorColor.hashCode ^
backgroundColor.hashCode ^
backgroundGradient.hashCode ^
borderColor.hashCode ^
borderRadius.hashCode ^
indicatorBorderRadius.hashCode ^
indicatorBorder.hashCode ^
indicatorBoxShadow.hashCode ^
boxShadow.hashCode;

// coverage:ignore-end
}
Loading

0 comments on commit 6dc4799

Please sign in to comment.