-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: re add puzzle quiz screen flow (#1430)
Co-authored-by: ookami-kb <ookami.kb@gmail.com>
- Loading branch information
1 parent
abf4eee
commit 126f7e8
Showing
9 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/espressocash_app/lib/features/backup_phrase/screens/puzzle_flow.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../utils/routing.dart'; | ||
import 'puzzle_input_screen.dart'; | ||
import 'puzzle_success_screen.dart'; | ||
import 'puzzle_view_phrase_screen.dart'; | ||
|
||
extension PuzzleFlow on BuildContext { | ||
void launchPuzzleFlow() { | ||
final navigator = Navigator.of(this, rootNavigator: true); | ||
|
||
MaterialPageRoute<void> successRoute() => MaterialPageRoute( | ||
builder: (context) => PuzzleSuccessScreen( | ||
onDone: () => context.openFirstScreen(), | ||
), | ||
); | ||
|
||
MaterialPageRoute<void> inputPhraseRoute(String phrase) => | ||
MaterialPageRoute( | ||
builder: (context) => PuzzleInputScreen( | ||
correctPhrase: phrase, | ||
onConfirmed: () => navigator.pushAndRemoveUntil( | ||
successRoute(), | ||
(route) => route.isFirst, | ||
), | ||
), | ||
); | ||
|
||
navigator.push<void>( | ||
MaterialPageRoute( | ||
builder: (context) => PuzzleViewPhraseScreen( | ||
onConfirmed: (phrase) => navigator.push(inputPhraseRoute(phrase)), | ||
), | ||
), | ||
); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/espressocash_app/lib/features/backup_phrase/screens/puzzle_input_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../../l10n/l10n.dart'; | ||
import '../../../../ui/app_bar.dart'; | ||
import '../../../../ui/onboarding_screen.dart'; | ||
import '../../../../ui/recovery_phrase_text_view.dart'; | ||
import '../../../../ui/theme.dart'; | ||
import '../widgets/grid_phrase.dart'; | ||
|
||
class PuzzleInputScreen extends StatefulWidget { | ||
const PuzzleInputScreen({ | ||
super.key, | ||
required this.correctPhrase, | ||
required this.onConfirmed, | ||
}); | ||
|
||
final String correctPhrase; | ||
final VoidCallback onConfirmed; | ||
|
||
@override | ||
State<PuzzleInputScreen> createState() => _PuzzleInputScreenState(); | ||
} | ||
|
||
class _PuzzleInputScreenState extends State<PuzzleInputScreen> { | ||
String _currentPhrase = ''; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final correctPhrase = widget.correctPhrase; | ||
|
||
return CpTheme.black( | ||
child: Scaffold( | ||
body: OnboardingScreen( | ||
footer: OnboardingFooterButton( | ||
text: context.l10n.next, | ||
onPressed: | ||
_currentPhrase == correctPhrase ? widget.onConfirmed : null, | ||
), | ||
children: [ | ||
const CpAppBar(), | ||
const OnboardingLogo(), | ||
OnboardingDescription(text: context.l10n.completeThePuzzle), | ||
OnboardingPadding( | ||
child: RecoveryPhraseTextView( | ||
phrase: _currentPhrase, | ||
hasCopyButton: false, | ||
), | ||
), | ||
const SizedBox(height: 32), | ||
SizedBox( | ||
height: 200, | ||
child: OnboardingPadding( | ||
child: GridPhrase( | ||
correctPhrase: widget.correctPhrase, | ||
callback: (phrase) => setState(() => _currentPhrase = phrase), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/espressocash_app/lib/features/backup_phrase/screens/puzzle_success_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../../../../gen/assets.gen.dart'; | ||
import '../../../../../../l10n/l10n.dart'; | ||
import '../../../../../../ui/button.dart'; | ||
import '../../../../../../ui/content_padding.dart'; | ||
import '../../../../../../ui/theme.dart'; | ||
import '../../../../ui/rounded_rectangle.dart'; | ||
import '../../../di.dart'; | ||
import '../services/puzzle_reminder_bloc.dart'; | ||
|
||
class PuzzleSuccessScreen extends StatelessWidget { | ||
const PuzzleSuccessScreen({super.key, required this.onDone}); | ||
|
||
final VoidCallback onDone; | ||
|
||
@override | ||
Widget build(BuildContext context) => CpTheme.black( | ||
child: Scaffold( | ||
body: CpContentPadding( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
const SizedBox(height: 110), | ||
Assets.icons.successCheck.svg(width: 72, height: 72), | ||
const SizedBox(height: 42), | ||
const CpRoundedRectangle( | ||
padding: EdgeInsets.all(32), | ||
backgroundColor: Colors.black, | ||
child: _SuccessMessage(), | ||
), | ||
const SizedBox(height: 80), | ||
CpButton( | ||
size: CpButtonSize.big, | ||
width: double.infinity, | ||
text: context.l10n.ok, | ||
onPressed: () { | ||
sl<PuzzleReminderBloc>() | ||
.add(const PuzzleReminderEvent.solved()); | ||
onDone(); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
class _SuccessMessage extends StatelessWidget { | ||
const _SuccessMessage(); | ||
|
||
@override | ||
Widget build(BuildContext context) => Text( | ||
context.l10n.backupPhrase_lblSuccessMessage, | ||
textAlign: TextAlign.center, | ||
style: const TextStyle(fontSize: 19, fontWeight: FontWeight.w400), | ||
); | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/espressocash_app/lib/features/backup_phrase/screens/puzzle_view_phrase_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../../di.dart'; | ||
import '../../../../l10n/l10n.dart'; | ||
import '../../../../ui/app_bar.dart'; | ||
import '../../../../ui/onboarding_screen.dart'; | ||
import '../../../../ui/recovery_phrase_text_view.dart'; | ||
import '../../../../ui/theme.dart'; | ||
import '../../accounts/data/account_repository.dart'; | ||
|
||
class PuzzleViewPhraseScreen extends StatefulWidget { | ||
const PuzzleViewPhraseScreen({ | ||
super.key, | ||
required this.onConfirmed, | ||
}); | ||
|
||
final ValueSetter<String> onConfirmed; | ||
|
||
@override | ||
State<PuzzleViewPhraseScreen> createState() => _PuzzleViewPhraseScreenState(); | ||
} | ||
|
||
class _PuzzleViewPhraseScreenState extends State<PuzzleViewPhraseScreen> { | ||
String _phrase = ''; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
sl<AccountRepository>().loadMnemonic().then((String? phrase) { | ||
if (phrase != null) { | ||
setState(() => _phrase = phrase); | ||
} | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) => CpTheme.black( | ||
child: Scaffold( | ||
body: OnboardingScreen( | ||
footer: OnboardingFooterButton( | ||
text: context.l10n.next, | ||
onPressed: () => widget.onConfirmed(_phrase), | ||
), | ||
children: [ | ||
const CpAppBar(), | ||
const OnboardingLogo(), | ||
OnboardingTitle(text: context.l10n.yourRecoveryPhrase), | ||
OnboardingDescription(text: context.l10n.yourRecoveryPhraseSub), | ||
OnboardingPadding( | ||
child: RecoveryPhraseTextView(phrase: _phrase), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters