Skip to content

Commit

Permalink
Disable button on loading
Browse files Browse the repository at this point in the history
  • Loading branch information
elianortega committed Apr 6, 2021
1 parent c0f4d4b commit c7eb14c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/src/features/jokes/logic/jokes_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import 'package:jokes/jokes.dart';

part 'jokes_state.freezed.dart';

extension JokesGetters on JokesState {
bool get isLoading => this is _Loading;
}

@freezed
abstract class JokesState with _$JokesState {
/// Data is present state
Expand Down
26 changes: 19 additions & 7 deletions lib/src/features/jokes/views/joke_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ class JokePage extends StatelessWidget {
children: [
const SizedBox(height: 5),
const JokeConsumer(),
CupertinoButton.filled(
key: getJokeButtonKey,
child: Text(kGiveMeAJoke.i18n),
onPressed: () {
context.read(jokesNotifierProvider.notifier).getJoke();
},
),
const _GetJokeButton(),
AppVersion(),
const SizedBox(height: 5),
],
Expand Down Expand Up @@ -78,3 +72,21 @@ class _Message extends StatelessWidget {
);
}
}

class _GetJokeButton extends ConsumerWidget {
const _GetJokeButton();
@override
Widget build(BuildContext context, ScopedReader watch) {
final state = watch(jokesNotifierProvider);

return CupertinoButton.filled(
key: getJokeButtonKey,
child: Text(kGiveMeAJoke.i18n),
onPressed: !state.isLoading
? () {
context.read(jokesNotifierProvider.notifier).getJoke();
}
: null,
);
}
}

0 comments on commit c7eb14c

Please sign in to comment.