Skip to content

Commit

Permalink
small merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
stargazing-dino committed May 25, 2022
2 parents 0074218 + c5ca263 commit 8988842
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 14 deletions.
27 changes: 23 additions & 4 deletions example/pubspec.lock
Expand Up @@ -74,6 +74,7 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
<<<<<<< HEAD
freezed_annotation:
dependency: transitive
description:
Expand All @@ -82,18 +83,22 @@ packages:
source: hosted
version: "2.0.0"
json_annotation:
=======
matcher:
>>>>>>> c5ca263f91a1078cabc1aa19e630edf1cfbb5bc2
dependency: transitive
description:
name: json_annotation
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.0"
matcher:
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: matcher
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
<<<<<<< HEAD
version: "0.12.11"
material_color_utilities:
dependency: transitive
Expand All @@ -102,6 +107,9 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
=======
version: "0.1.3"
>>>>>>> c5ca263f91a1078cabc1aa19e630edf1cfbb5bc2
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -169,7 +177,18 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
<<<<<<< HEAD
version: "0.4.9"
=======
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
>>>>>>> c5ca263f91a1078cabc1aa19e630edf1cfbb5bc2
vector_math:
dependency: transitive
description:
Expand Down
16 changes: 13 additions & 3 deletions lib/src/async_button_builder.dart
Expand Up @@ -81,6 +81,12 @@ class AsyncButtonBuilder extends StatefulWidget {
/// completes.
final AsyncCallback? onPressed;

/// A callback that runs [buttonState] changes to [ButtonState.success]
final VoidCallback? onSuccess;

/// A callback that runs [buttonState] changes to [ButtonState.error]
final VoidCallback? onError;

/// This is used to manually drive the state of the loading button thus
/// initiating the corresponding animation and showing the correct button
/// child.
Expand Down Expand Up @@ -200,6 +206,8 @@ class AsyncButtonBuilder extends StatefulWidget {
required this.child,
required this.onPressed,
required this.builder,
this.onSuccess,
this.onError,
this.loadingWidget,
this.successWidget,
this.errorWidget,
Expand Down Expand Up @@ -390,7 +398,7 @@ class _AsyncButtonBuilderState extends State<AsyncButtonBuilder>
buttonState = const ButtonState.success();
});

setTimer(widget.successDuration);
setTimer(widget.successDuration, widget.onSuccess);
} else {
setState(() {
buttonState = const ButtonState.idle();
Expand All @@ -406,7 +414,7 @@ class _AsyncButtonBuilderState extends State<AsyncButtonBuilder>
buttonState = const ButtonState.error();
});

setTimer(widget.errorDuration);
setTimer(widget.errorDuration, widget.onSuccess);
} else {
setState(() {
buttonState = const ButtonState.idle();
Expand All @@ -423,12 +431,14 @@ class _AsyncButtonBuilderState extends State<AsyncButtonBuilder>
);
}

void setTimer(Duration duration) {
void setTimer(Duration duration, [VoidCallback? then]) {
timer = Timer(
duration,
() {
timer?.cancel();

then?.call();

if (mounted) {
setState(() {
buttonState = const ButtonState.idle();
Expand Down
4 changes: 1 addition & 3 deletions lib/src/button_state/button_state.dart
@@ -1,5 +1,3 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'button_state.freezed.dart';

/// This union class represents the state of the button in either a [Idling],
Expand Down Expand Up @@ -30,7 +28,7 @@ part 'button_state.freezed.dart';
/// );
/// ```
/// {@end-tool}
@freezed
// @freezed
class ButtonState with _$ButtonState {
const factory ButtonState.idle() = Idle;
const factory ButtonState.loading() = Loading;
Expand Down
168 changes: 168 additions & 0 deletions pubspec.lock
@@ -0,0 +1,168 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.17.0"
5 changes: 1 addition & 4 deletions pubspec.yaml
Expand Up @@ -11,12 +11,9 @@ environment:
dependencies:
flutter:
sdk: flutter
freezed_annotation: ^2.0.0

dev_dependencies:
build_runner: ^2.1.10
freezed: ^2.0.0
flutter_lints: ^1.0.4
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter

Expand Down

0 comments on commit 8988842

Please sign in to comment.