feat: Add refresh indicator on Recovery Key page to support drag gestures #148

Merged
inex merged 1 commits from recovery-keys into master 2022-11-22 14:07:24 +02:00
1 changed files with 17 additions and 6 deletions

View File

@ -21,6 +21,12 @@ class RecoveryKey extends StatefulWidget {
}
class _RecoveryKeyState extends State<RecoveryKey> {
@override
void initState() {
super.initState();
context.read<RecoveryKeyCubit>().load();
}

Something feels wrong with this approach.

If you want to do something on the first draw, you use initState. Example here. Documentation.

I don't see why we need this loadedOnOpening bool variable. If you just need to ping cubit on the page entry, use initState.

Something feels wrong with this approach. If you want to do something on the first draw, you use initState. [Example here](https://git.selfprivacy.org/kherel/selfprivacy.org.app/src/branch/master/lib/ui/components/brand_tab_bar/brand_tab_bar.dart#L15). [Documentation](https://api.flutter.dev/flutter/widgets/State/initState.html). I don't see why we need this `loadedOnOpening` bool variable. If you just need to ping cubit on the page entry, use initState.

But initState doesn't have context. This is essentially the same thing as this check.

But initState doesn't have context. This is essentially the same thing as [this check](https://git.selfprivacy.org/kherel/selfprivacy.org.app/src/commit/0639ee4d57317b5c9d045287b297c5e8b43f6445/lib/ui/pages/server_storage/binds_migration/migration_process_page.dart#L32).

Oops, no, wrong link, but you get what I wanted to say.

Oops, no, wrong link, but you get what I wanted to say.
@override
Widget build(final BuildContext context) {
final RecoveryKeyState keyStatus = context.watch<RecoveryKeyCubit>().state;
@ -50,12 +56,17 @@ class _RecoveryKeyState extends State<RecoveryKey> {
break;
}
return BrandHeroScreen(
heroTitle: 'recovery_key.key_main_header'.tr(),
heroSubtitle: subtitle,
hasBackButton: true,
hasFlashButton: false,
children: widgets,
return RefreshIndicator(
onRefresh: () async {
context.read<RecoveryKeyCubit>().load();
},
child: BrandHeroScreen(
heroTitle: 'recovery_key.key_main_header'.tr(),
heroSubtitle: subtitle,
hasBackButton: true,
hasFlashButton: false,
children: widgets,
),
);
}
}