diff --git a/.run/example.run.xml b/.run/example.run.xml new file mode 100644 index 0000000..5650683 --- /dev/null +++ b/.run/example.run.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index c6759a6..deb66de 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -127,7 +127,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..3db53b6 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =2.12.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=1.17.0" diff --git a/lib/pressable.dart b/lib/pressable.dart index 08e0466..3b4d20e 100644 --- a/lib/pressable.dart +++ b/lib/pressable.dart @@ -4,14 +4,17 @@ import 'package:flutter/material.dart'; import 'package:pressable/src/builder.dart'; import 'package:pressable/src/fill.dart'; import 'package:pressable/src/opacity.dart'; +import 'package:pressable/src/platform.dart'; import 'package:pressable/src/ripple.dart'; import 'package:pressable/src/scale.dart'; +import 'package:pressable/src/theme/theme.dart'; -export 'package:pressable/src/builder.dart' show PressableBuilderCallback; -export 'package:pressable/src/fill.dart' show PressableFillTheme; -export 'package:pressable/src/opacity.dart' show PressableOpacityTheme; -export 'package:pressable/src/ripple.dart' show PressableRippleTheme; -export 'package:pressable/src/scale.dart' show PressableScaleTheme; +export 'package:pressable/src/builder.dart'; +export 'package:pressable/src/fill.dart'; +export 'package:pressable/src/opacity.dart'; +export 'package:pressable/src/ripple.dart'; +export 'package:pressable/src/scale.dart'; +export 'package:pressable/src/theme/theme.dart'; /// Choose named constructors to pick press effect. abstract class Pressable extends StatefulWidget { @@ -90,6 +93,32 @@ abstract class Pressable extends StatefulWidget { ); } + /// Provide platform specific [PressableTheme]. You must provide theme for + /// current platform otherwise error is thrown. + factory Pressable.platform({ + Key? key, + required Widget child, + VoidCallback? onPressed, + VoidCallback? onLongPressed, + PressableTheme? ios, + PressableTheme? android, + PressableTheme? macOS, + PressableTheme? windows, + PressableTheme? linux, + }) { + return PressablePlatform( + key: key, + ios: ios, + macOS: macOS, + windows: windows, + linux: linux, + android: android, + onPressed: onPressed, + onLongPressed: onLongPressed, + child: child, + ); + } + /// Use builder to define your own effect. factory Pressable.builder({ Key? key, diff --git a/lib/src/base.dart b/lib/src/base.dart index 2afd2df..eff1863 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -1,4 +1,3 @@ -import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; abstract class PressableBaseState extends State { diff --git a/lib/src/fill.dart b/lib/src/fill.dart index bda3102..9de368d 100644 --- a/lib/src/fill.dart +++ b/lib/src/fill.dart @@ -1,4 +1,3 @@ -import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:pressable/pressable.dart'; import 'package:pressable/src/base.dart'; @@ -35,16 +34,3 @@ class _PressableFillState extends PressableBaseState { ); } } - -class PressableFillTheme extends Equatable { - const PressableFillTheme({ - this.fillColor = Colors.black38, - this.borderRadius = BorderRadius.zero, - }); - - final Color fillColor; - final BorderRadius borderRadius; - - @override - List get props => [fillColor, borderRadius]; -} diff --git a/lib/src/opacity.dart b/lib/src/opacity.dart index 61f514b..010d028 100644 --- a/lib/src/opacity.dart +++ b/lib/src/opacity.dart @@ -1,4 +1,3 @@ -import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:pressable/pressable.dart'; import 'package:pressable/src/base.dart'; @@ -40,20 +39,3 @@ class _PressableOpacityState extends PressableBaseState { ); } } - -class PressableOpacityTheme extends Equatable { - const PressableOpacityTheme({ - this.duration = const Duration(milliseconds: 100), - this.curve = Curves.linear, - this.opacityFactor = 0.6, - this.backgroundColor = Colors.transparent, - }); - - final Duration duration; - final double opacityFactor; - final Curve curve; - final Color backgroundColor; - - @override - List get props => [duration, opacityFactor, curve, backgroundColor]; -} diff --git a/lib/src/platform.dart b/lib/src/platform.dart new file mode 100644 index 0000000..ad05ba8 --- /dev/null +++ b/lib/src/platform.dart @@ -0,0 +1,93 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:pressable/pressable.dart'; + +class PressablePlatform extends Pressable { + const PressablePlatform({ + Key? key, + required this.child, + this.onPressed, + this.onLongPressed, + this.ios, + this.android, + this.macOS, + this.windows, + this.linux, + }) : super(key: key); + + final Widget child; + final VoidCallback? onPressed; + final VoidCallback? onLongPressed; + final PressableTheme? ios; + final PressableTheme? android; + final PressableTheme? macOS; + final PressableTheme? windows; + final PressableTheme? linux; + + @override + _PressablePlatformState createState() => _PressablePlatformState(); +} + +class _PressablePlatformState extends State { + @override + Widget build(BuildContext context) { + PressableTheme? pressable; + if (Platform.isIOS) { + pressable = widget.ios; + } + if (Platform.isAndroid) { + pressable = widget.android; + } + if (Platform.isMacOS) { + pressable = widget.macOS; + } + if (Platform.isWindows) { + pressable = widget.windows; + } + if (Platform.isLinux) { + pressable = widget.linux; + } + + if (pressable == null) { + throw ArgumentError( + 'PressableTheme for current platform is not provided.', + ); + } + + return pressable.map( + ripple: (theme) { + return Pressable.ripple( + onPressed: widget.onPressed, + onLongPressed: widget.onLongPressed, + theme: theme, + child: widget.child, + ); + }, + scale: (theme) { + return Pressable.scale( + onPressed: widget.onPressed, + onLongPressed: widget.onLongPressed, + theme: theme, + child: widget.child, + ); + }, + opacity: (theme) { + return Pressable.opacity( + onPressed: widget.onPressed, + onLongPressed: widget.onLongPressed, + theme: theme, + child: widget.child, + ); + }, + fill: (theme) { + return Pressable.fill( + onPressed: widget.onPressed, + onLongPressed: widget.onLongPressed, + theme: theme, + child: widget.child, + ); + }, + ); + } +} diff --git a/lib/src/ripple.dart b/lib/src/ripple.dart index 5a70a38..0259f7a 100644 --- a/lib/src/ripple.dart +++ b/lib/src/ripple.dart @@ -1,4 +1,3 @@ -import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:pressable/pressable.dart'; @@ -34,18 +33,3 @@ class _PressableRippleState extends State { ); } } - -class PressableRippleTheme extends Equatable { - const PressableRippleTheme({ - this.splashColor, - this.highlightColor, - this.borderRadius, - }); - - final Color? splashColor; - final Color? highlightColor; - final BorderRadius? borderRadius; - - @override - List get props => [splashColor, highlightColor, borderRadius]; -} diff --git a/lib/src/scale.dart b/lib/src/scale.dart index a4b9b3a..96e5aff 100644 --- a/lib/src/scale.dart +++ b/lib/src/scale.dart @@ -1,4 +1,3 @@ -import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:pressable/pressable.dart'; import 'package:pressable/src/base.dart'; @@ -85,18 +84,3 @@ class _PressableScaleState extends PressableBaseState super.dispose(); } } - -class PressableScaleTheme extends Equatable { - const PressableScaleTheme({ - this.scaleFactor = 0.6, - this.duration = const Duration(milliseconds: 100), - this.curve = Curves.easeInOut, - }); - - final double scaleFactor; - final Duration duration; - final Curve curve; - - @override - List get props => [scaleFactor, duration, curve]; -} diff --git a/lib/src/theme/theme.dart b/lib/src/theme/theme.dart new file mode 100644 index 0000000..f5c3de6 --- /dev/null +++ b/lib/src/theme/theme.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'theme.freezed.dart'; + +@freezed +class PressableTheme with _$PressableTheme { + const factory PressableTheme.ripple({ + Color? splashColor, + Color? highlightColor, + BorderRadius? borderRadius, + }) = PressableRippleTheme; + + const factory PressableTheme.scale({ + @Default(0.8) double scaleFactor, + @Default(Duration(milliseconds: 100)) Duration duration, + @Default(Curves.easeInOut) Curve curve, + }) = PressableScaleTheme; + + const factory PressableTheme.opacity({ + @Default(Duration(milliseconds: 100)) Duration duration, + @Default(0.6) double opacityFactor, + @Default(Curves.linear) Curve curve, + @Default(Colors.transparent) Color backgroundColor, + }) = PressableOpacityTheme; + + const factory PressableTheme.fill({ + @Default(Colors.black38) Color fillColor, + @Default(BorderRadius.zero) BorderRadius borderRadius, + }) = PressableFillTheme; +} diff --git a/lib/src/theme/theme.freezed.dart b/lib/src/theme/theme.freezed.dart new file mode 100644 index 0000000..0992688 --- /dev/null +++ b/lib/src/theme/theme.freezed.dart @@ -0,0 +1,917 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of 'theme.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$PressableThemeTearOff { + const _$PressableThemeTearOff(); + + PressableRippleTheme ripple( + {Color? splashColor, Color? highlightColor, BorderRadius? borderRadius}) { + return PressableRippleTheme( + splashColor: splashColor, + highlightColor: highlightColor, + borderRadius: borderRadius, + ); + } + + PressableScaleTheme scale( + {double scaleFactor = 0.8, + Duration duration = const Duration(milliseconds: 100), + Curve curve = Curves.easeInOut}) { + return PressableScaleTheme( + scaleFactor: scaleFactor, + duration: duration, + curve: curve, + ); + } + + PressableOpacityTheme opacity( + {Duration duration = const Duration(milliseconds: 100), + double opacityFactor = 0.6, + Curve curve = Curves.linear, + Color backgroundColor = Colors.transparent}) { + return PressableOpacityTheme( + duration: duration, + opacityFactor: opacityFactor, + curve: curve, + backgroundColor: backgroundColor, + ); + } + + PressableFillTheme fill( + {Color fillColor = Colors.black38, + BorderRadius borderRadius = BorderRadius.zero}) { + return PressableFillTheme( + fillColor: fillColor, + borderRadius: borderRadius, + ); + } +} + +/// @nodoc +const $PressableTheme = _$PressableThemeTearOff(); + +/// @nodoc +mixin _$PressableTheme { + @optionalTypeArgs + TResult when({ + required TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius) + ripple, + required TResult Function( + double scaleFactor, Duration duration, Curve curve) + scale, + required TResult Function(Duration duration, double opacityFactor, + Curve curve, Color backgroundColor) + opacity, + required TResult Function(Color fillColor, BorderRadius borderRadius) fill, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(PressableRippleTheme value) ripple, + required TResult Function(PressableScaleTheme value) scale, + required TResult Function(PressableOpacityTheme value) opacity, + required TResult Function(PressableFillTheme value) fill, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PressableThemeCopyWith<$Res> { + factory $PressableThemeCopyWith( + PressableTheme value, $Res Function(PressableTheme) then) = + _$PressableThemeCopyWithImpl<$Res>; +} + +/// @nodoc +class _$PressableThemeCopyWithImpl<$Res> + implements $PressableThemeCopyWith<$Res> { + _$PressableThemeCopyWithImpl(this._value, this._then); + + final PressableTheme _value; + // ignore: unused_field + final $Res Function(PressableTheme) _then; +} + +/// @nodoc +abstract class $PressableRippleThemeCopyWith<$Res> { + factory $PressableRippleThemeCopyWith(PressableRippleTheme value, + $Res Function(PressableRippleTheme) then) = + _$PressableRippleThemeCopyWithImpl<$Res>; + $Res call( + {Color? splashColor, Color? highlightColor, BorderRadius? borderRadius}); +} + +/// @nodoc +class _$PressableRippleThemeCopyWithImpl<$Res> + extends _$PressableThemeCopyWithImpl<$Res> + implements $PressableRippleThemeCopyWith<$Res> { + _$PressableRippleThemeCopyWithImpl( + PressableRippleTheme _value, $Res Function(PressableRippleTheme) _then) + : super(_value, (v) => _then(v as PressableRippleTheme)); + + @override + PressableRippleTheme get _value => super._value as PressableRippleTheme; + + @override + $Res call({ + Object? splashColor = freezed, + Object? highlightColor = freezed, + Object? borderRadius = freezed, + }) { + return _then(PressableRippleTheme( + splashColor: splashColor == freezed + ? _value.splashColor + : splashColor // ignore: cast_nullable_to_non_nullable + as Color?, + highlightColor: highlightColor == freezed + ? _value.highlightColor + : highlightColor // ignore: cast_nullable_to_non_nullable + as Color?, + borderRadius: borderRadius == freezed + ? _value.borderRadius + : borderRadius // ignore: cast_nullable_to_non_nullable + as BorderRadius?, + )); + } +} + +/// @nodoc + +class _$PressableRippleTheme implements PressableRippleTheme { + const _$PressableRippleTheme( + {this.splashColor, this.highlightColor, this.borderRadius}); + + @override + final Color? splashColor; + @override + final Color? highlightColor; + @override + final BorderRadius? borderRadius; + + @override + String toString() { + return 'PressableTheme.ripple(splashColor: $splashColor, highlightColor: $highlightColor, borderRadius: $borderRadius)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PressableRippleTheme && + const DeepCollectionEquality() + .equals(other.splashColor, splashColor) && + const DeepCollectionEquality() + .equals(other.highlightColor, highlightColor) && + const DeepCollectionEquality() + .equals(other.borderRadius, borderRadius)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(splashColor), + const DeepCollectionEquality().hash(highlightColor), + const DeepCollectionEquality().hash(borderRadius)); + + @JsonKey(ignore: true) + @override + $PressableRippleThemeCopyWith get copyWith => + _$PressableRippleThemeCopyWithImpl( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius) + ripple, + required TResult Function( + double scaleFactor, Duration duration, Curve curve) + scale, + required TResult Function(Duration duration, double opacityFactor, + Curve curve, Color backgroundColor) + opacity, + required TResult Function(Color fillColor, BorderRadius borderRadius) fill, + }) { + return ripple(splashColor, highlightColor, borderRadius); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + }) { + return ripple?.call(splashColor, highlightColor, borderRadius); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + required TResult orElse(), + }) { + if (ripple != null) { + return ripple(splashColor, highlightColor, borderRadius); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(PressableRippleTheme value) ripple, + required TResult Function(PressableScaleTheme value) scale, + required TResult Function(PressableOpacityTheme value) opacity, + required TResult Function(PressableFillTheme value) fill, + }) { + return ripple(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + }) { + return ripple?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + required TResult orElse(), + }) { + if (ripple != null) { + return ripple(this); + } + return orElse(); + } +} + +abstract class PressableRippleTheme implements PressableTheme { + const factory PressableRippleTheme( + {Color? splashColor, + Color? highlightColor, + BorderRadius? borderRadius}) = _$PressableRippleTheme; + + Color? get splashColor; + Color? get highlightColor; + BorderRadius? get borderRadius; + @JsonKey(ignore: true) + $PressableRippleThemeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PressableScaleThemeCopyWith<$Res> { + factory $PressableScaleThemeCopyWith( + PressableScaleTheme value, $Res Function(PressableScaleTheme) then) = + _$PressableScaleThemeCopyWithImpl<$Res>; + $Res call({double scaleFactor, Duration duration, Curve curve}); +} + +/// @nodoc +class _$PressableScaleThemeCopyWithImpl<$Res> + extends _$PressableThemeCopyWithImpl<$Res> + implements $PressableScaleThemeCopyWith<$Res> { + _$PressableScaleThemeCopyWithImpl( + PressableScaleTheme _value, $Res Function(PressableScaleTheme) _then) + : super(_value, (v) => _then(v as PressableScaleTheme)); + + @override + PressableScaleTheme get _value => super._value as PressableScaleTheme; + + @override + $Res call({ + Object? scaleFactor = freezed, + Object? duration = freezed, + Object? curve = freezed, + }) { + return _then(PressableScaleTheme( + scaleFactor: scaleFactor == freezed + ? _value.scaleFactor + : scaleFactor // ignore: cast_nullable_to_non_nullable + as double, + duration: duration == freezed + ? _value.duration + : duration // ignore: cast_nullable_to_non_nullable + as Duration, + curve: curve == freezed + ? _value.curve + : curve // ignore: cast_nullable_to_non_nullable + as Curve, + )); + } +} + +/// @nodoc + +class _$PressableScaleTheme implements PressableScaleTheme { + const _$PressableScaleTheme( + {this.scaleFactor = 0.8, + this.duration = const Duration(milliseconds: 100), + this.curve = Curves.easeInOut}); + + @JsonKey() + @override + final double scaleFactor; + @JsonKey() + @override + final Duration duration; + @JsonKey() + @override + final Curve curve; + + @override + String toString() { + return 'PressableTheme.scale(scaleFactor: $scaleFactor, duration: $duration, curve: $curve)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PressableScaleTheme && + const DeepCollectionEquality() + .equals(other.scaleFactor, scaleFactor) && + const DeepCollectionEquality().equals(other.duration, duration) && + const DeepCollectionEquality().equals(other.curve, curve)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(scaleFactor), + const DeepCollectionEquality().hash(duration), + const DeepCollectionEquality().hash(curve)); + + @JsonKey(ignore: true) + @override + $PressableScaleThemeCopyWith get copyWith => + _$PressableScaleThemeCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius) + ripple, + required TResult Function( + double scaleFactor, Duration duration, Curve curve) + scale, + required TResult Function(Duration duration, double opacityFactor, + Curve curve, Color backgroundColor) + opacity, + required TResult Function(Color fillColor, BorderRadius borderRadius) fill, + }) { + return scale(scaleFactor, duration, curve); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + }) { + return scale?.call(scaleFactor, duration, curve); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + required TResult orElse(), + }) { + if (scale != null) { + return scale(scaleFactor, duration, curve); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(PressableRippleTheme value) ripple, + required TResult Function(PressableScaleTheme value) scale, + required TResult Function(PressableOpacityTheme value) opacity, + required TResult Function(PressableFillTheme value) fill, + }) { + return scale(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + }) { + return scale?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + required TResult orElse(), + }) { + if (scale != null) { + return scale(this); + } + return orElse(); + } +} + +abstract class PressableScaleTheme implements PressableTheme { + const factory PressableScaleTheme( + {double scaleFactor, + Duration duration, + Curve curve}) = _$PressableScaleTheme; + + double get scaleFactor; + Duration get duration; + Curve get curve; + @JsonKey(ignore: true) + $PressableScaleThemeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PressableOpacityThemeCopyWith<$Res> { + factory $PressableOpacityThemeCopyWith(PressableOpacityTheme value, + $Res Function(PressableOpacityTheme) then) = + _$PressableOpacityThemeCopyWithImpl<$Res>; + $Res call( + {Duration duration, + double opacityFactor, + Curve curve, + Color backgroundColor}); +} + +/// @nodoc +class _$PressableOpacityThemeCopyWithImpl<$Res> + extends _$PressableThemeCopyWithImpl<$Res> + implements $PressableOpacityThemeCopyWith<$Res> { + _$PressableOpacityThemeCopyWithImpl( + PressableOpacityTheme _value, $Res Function(PressableOpacityTheme) _then) + : super(_value, (v) => _then(v as PressableOpacityTheme)); + + @override + PressableOpacityTheme get _value => super._value as PressableOpacityTheme; + + @override + $Res call({ + Object? duration = freezed, + Object? opacityFactor = freezed, + Object? curve = freezed, + Object? backgroundColor = freezed, + }) { + return _then(PressableOpacityTheme( + duration: duration == freezed + ? _value.duration + : duration // ignore: cast_nullable_to_non_nullable + as Duration, + opacityFactor: opacityFactor == freezed + ? _value.opacityFactor + : opacityFactor // ignore: cast_nullable_to_non_nullable + as double, + curve: curve == freezed + ? _value.curve + : curve // ignore: cast_nullable_to_non_nullable + as Curve, + backgroundColor: backgroundColor == freezed + ? _value.backgroundColor + : backgroundColor // ignore: cast_nullable_to_non_nullable + as Color, + )); + } +} + +/// @nodoc + +class _$PressableOpacityTheme implements PressableOpacityTheme { + const _$PressableOpacityTheme( + {this.duration = const Duration(milliseconds: 100), + this.opacityFactor = 0.6, + this.curve = Curves.linear, + this.backgroundColor = Colors.transparent}); + + @JsonKey() + @override + final Duration duration; + @JsonKey() + @override + final double opacityFactor; + @JsonKey() + @override + final Curve curve; + @JsonKey() + @override + final Color backgroundColor; + + @override + String toString() { + return 'PressableTheme.opacity(duration: $duration, opacityFactor: $opacityFactor, curve: $curve, backgroundColor: $backgroundColor)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PressableOpacityTheme && + const DeepCollectionEquality().equals(other.duration, duration) && + const DeepCollectionEquality() + .equals(other.opacityFactor, opacityFactor) && + const DeepCollectionEquality().equals(other.curve, curve) && + const DeepCollectionEquality() + .equals(other.backgroundColor, backgroundColor)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(duration), + const DeepCollectionEquality().hash(opacityFactor), + const DeepCollectionEquality().hash(curve), + const DeepCollectionEquality().hash(backgroundColor)); + + @JsonKey(ignore: true) + @override + $PressableOpacityThemeCopyWith get copyWith => + _$PressableOpacityThemeCopyWithImpl( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius) + ripple, + required TResult Function( + double scaleFactor, Duration duration, Curve curve) + scale, + required TResult Function(Duration duration, double opacityFactor, + Curve curve, Color backgroundColor) + opacity, + required TResult Function(Color fillColor, BorderRadius borderRadius) fill, + }) { + return opacity(duration, opacityFactor, curve, backgroundColor); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + }) { + return opacity?.call(duration, opacityFactor, curve, backgroundColor); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + required TResult orElse(), + }) { + if (opacity != null) { + return opacity(duration, opacityFactor, curve, backgroundColor); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(PressableRippleTheme value) ripple, + required TResult Function(PressableScaleTheme value) scale, + required TResult Function(PressableOpacityTheme value) opacity, + required TResult Function(PressableFillTheme value) fill, + }) { + return opacity(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + }) { + return opacity?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + required TResult orElse(), + }) { + if (opacity != null) { + return opacity(this); + } + return orElse(); + } +} + +abstract class PressableOpacityTheme implements PressableTheme { + const factory PressableOpacityTheme( + {Duration duration, + double opacityFactor, + Curve curve, + Color backgroundColor}) = _$PressableOpacityTheme; + + Duration get duration; + double get opacityFactor; + Curve get curve; + Color get backgroundColor; + @JsonKey(ignore: true) + $PressableOpacityThemeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PressableFillThemeCopyWith<$Res> { + factory $PressableFillThemeCopyWith( + PressableFillTheme value, $Res Function(PressableFillTheme) then) = + _$PressableFillThemeCopyWithImpl<$Res>; + $Res call({Color fillColor, BorderRadius borderRadius}); +} + +/// @nodoc +class _$PressableFillThemeCopyWithImpl<$Res> + extends _$PressableThemeCopyWithImpl<$Res> + implements $PressableFillThemeCopyWith<$Res> { + _$PressableFillThemeCopyWithImpl( + PressableFillTheme _value, $Res Function(PressableFillTheme) _then) + : super(_value, (v) => _then(v as PressableFillTheme)); + + @override + PressableFillTheme get _value => super._value as PressableFillTheme; + + @override + $Res call({ + Object? fillColor = freezed, + Object? borderRadius = freezed, + }) { + return _then(PressableFillTheme( + fillColor: fillColor == freezed + ? _value.fillColor + : fillColor // ignore: cast_nullable_to_non_nullable + as Color, + borderRadius: borderRadius == freezed + ? _value.borderRadius + : borderRadius // ignore: cast_nullable_to_non_nullable + as BorderRadius, + )); + } +} + +/// @nodoc + +class _$PressableFillTheme implements PressableFillTheme { + const _$PressableFillTheme( + {this.fillColor = Colors.black38, this.borderRadius = BorderRadius.zero}); + + @JsonKey() + @override + final Color fillColor; + @JsonKey() + @override + final BorderRadius borderRadius; + + @override + String toString() { + return 'PressableTheme.fill(fillColor: $fillColor, borderRadius: $borderRadius)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PressableFillTheme && + const DeepCollectionEquality().equals(other.fillColor, fillColor) && + const DeepCollectionEquality() + .equals(other.borderRadius, borderRadius)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(fillColor), + const DeepCollectionEquality().hash(borderRadius)); + + @JsonKey(ignore: true) + @override + $PressableFillThemeCopyWith get copyWith => + _$PressableFillThemeCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius) + ripple, + required TResult Function( + double scaleFactor, Duration duration, Curve curve) + scale, + required TResult Function(Duration duration, double opacityFactor, + Curve curve, Color backgroundColor) + opacity, + required TResult Function(Color fillColor, BorderRadius borderRadius) fill, + }) { + return fill(fillColor, borderRadius); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + }) { + return fill?.call(fillColor, borderRadius); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(Color? splashColor, Color? highlightColor, + BorderRadius? borderRadius)? + ripple, + TResult Function(double scaleFactor, Duration duration, Curve curve)? scale, + TResult Function(Duration duration, double opacityFactor, Curve curve, + Color backgroundColor)? + opacity, + TResult Function(Color fillColor, BorderRadius borderRadius)? fill, + required TResult orElse(), + }) { + if (fill != null) { + return fill(fillColor, borderRadius); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(PressableRippleTheme value) ripple, + required TResult Function(PressableScaleTheme value) scale, + required TResult Function(PressableOpacityTheme value) opacity, + required TResult Function(PressableFillTheme value) fill, + }) { + return fill(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + }) { + return fill?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(PressableRippleTheme value)? ripple, + TResult Function(PressableScaleTheme value)? scale, + TResult Function(PressableOpacityTheme value)? opacity, + TResult Function(PressableFillTheme value)? fill, + required TResult orElse(), + }) { + if (fill != null) { + return fill(this); + } + return orElse(); + } +} + +abstract class PressableFillTheme implements PressableTheme { + const factory PressableFillTheme( + {Color fillColor, BorderRadius borderRadius}) = _$PressableFillTheme; + + Color get fillColor; + BorderRadius get borderRadius; + @JsonKey(ignore: true) + $PressableFillThemeCopyWith get copyWith => + throw _privateConstructorUsedError; +} diff --git a/pubspec.lock b/pubspec.lock index 7337c58..7d2db56 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "33.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -15,13 +36,69 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + build: + dependency: transitive + description: + name: build + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + build_config: + dependency: transitive + description: + name: build_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + build_daemon: + dependency: transitive + description: + name: build_daemon + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" + build_runner: + dependency: "direct dev" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.7" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + url: "https://pub.dartlang.org" + source: hosted + version: "7.2.3" + built_collection: + dependency: transitive + description: + name: built_collection + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + url: "https://pub.dartlang.org" + source: hosted + version: "8.1.4" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: @@ -29,6 +106,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.5" clock: dependency: transitive description: @@ -36,6 +127,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + code_builder: + dependency: transitive + description: + name: code_builder + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" collection: dependency: transitive description: @@ -43,6 +141,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" equatable: dependency: "direct main" description: @@ -57,6 +176,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" flutter: dependency: "direct main" description: flutter @@ -74,6 +207,76 @@ packages: description: flutter source: sdk version: "0.0.0" + freezed: + dependency: "direct dev" + description: + name: freezed + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.4.0" lints: dependency: transitive description: @@ -81,13 +284,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: @@ -95,6 +305,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.0" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" path: dependency: transitive description: @@ -102,11 +326,53 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" source_span: dependency: transitive description: @@ -128,6 +394,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" string_scanner: dependency: transitive description: @@ -148,7 +421,14 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.2" + version: "0.4.3" + timing: + dependency: transitive + description: + name: timing + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" typed_data: dependency: transitive description: @@ -162,7 +442,28 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted + version: "2.1.1" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted version: "2.1.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index ba8b6be..61aeefb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,10 +11,13 @@ dependencies: equatable: ^2.0.3 flutter: sdk: flutter + freezed_annotation: ^1.1.0 dev_dependencies: + build_runner: ^2.1.7 flutter_lints: ^1.0.4 flutter_test: sdk: flutter + freezed: ^1.1.0 flutter: