Skip to content

Commit

Permalink
fix: Dark status bar for onboarding (openfoodfacts#2864)
Browse files Browse the repository at this point in the history
* Ensure all screens from the onboarding have a dark status bar (issue on iOS)

* Also apply to KnowledgePanelPage

* Ensure the "Authorize" button has a splash color

* Format dart code

* Useless print statement removed

* Knowledge panel card: Only force the status bar brightness on the walkthrough

* Revert to the initial implementation

* Dart format
  • Loading branch information
g123k authored Sep 6, 2022
1 parent 513af0e commit e8c97e4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_expa
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_group_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_page.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_summary_card.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

class KnowledgePanelCard extends StatelessWidget {
const KnowledgePanelCard({
Expand Down Expand Up @@ -54,14 +55,20 @@ class KnowledgePanelCard extends StatelessWidget {
margin: EdgeInsets.zero,
),
onTap: () {
final Brightness? brightness =
SmoothBrightnessOverride.of(context)?.brightness;

Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => KnowledgePanelPage(
groupElement: group,
panel: panel,
allPanels: allPanels,
product: product,
builder: (BuildContext context) => SmoothBrightnessOverride(
brightness: brightness,
child: KnowledgePanelPage(
groupElement: group,
panel: panel,
allPanels: allPanels,
product: product,
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class OnboardingFlowNavigator {
child: Builder(
builder: (BuildContext context) => SmoothScaffold(
body: widget,
brightness: Brightness.dark,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ReinventionPage extends StatelessWidget {

return SmoothScaffold(
backgroundColor: backgroundColor,
brightness: Brightness.dark,
body: SafeArea(
child: Stack(
children: <Widget>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/pages/onboarding/knowledge_panel_page_template.dart';
import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

class SampleHealthCardPage extends StatelessWidget {
const SampleHealthCardPage(this._localDatabase, this.backgroundColor);
Expand All @@ -11,13 +12,16 @@ class SampleHealthCardPage extends StatelessWidget {
final Color backgroundColor;

@override
Widget build(BuildContext context) => KnowledgePanelPageTemplate(
headerTitle: AppLocalizations.of(context).healthCardUtility,
page: OnboardingPage.HEALTH_CARD_EXAMPLE,
panelId: 'health_card',
localDatabase: _localDatabase,
backgroundColor: backgroundColor,
svgAsset: 'assets/onboarding/health.svg',
nextKey: const Key('nextAfterHealth'),
Widget build(BuildContext context) => SmoothBrightnessOverride(
brightness: Brightness.dark,
child: KnowledgePanelPageTemplate(
headerTitle: AppLocalizations.of(context).healthCardUtility,
page: OnboardingPage.HEALTH_CARD_EXAMPLE,
panelId: 'health_card',
localDatabase: _localDatabase,
backgroundColor: backgroundColor,
svgAsset: 'assets/onboarding/health.svg',
nextKey: const Key('nextAfterHealth'),
),
);
}
1 change: 1 addition & 0 deletions packages/smooth_app/lib/pages/onboarding/welcome_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class WelcomePage extends StatelessWidget {

return SmoothScaffold(
backgroundColor: backgroundColor,
brightness: Brightness.dark,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
33 changes: 31 additions & 2 deletions packages/smooth_app/lib/widgets/smooth_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ class SmoothScaffoldState extends ScaffoldState {

return AnnotatedRegion<SystemUiOverlayStyle>(
value: _overlayStyle,
child: child,
child: Theme(
data: Theme.of(context).copyWith(
appBarTheme: AppBarTheme.of(context)
.copyWith(systemOverlayStyle: _overlayStyle),
),
child: child,
),
);
}

Expand All @@ -110,7 +116,9 @@ class SmoothScaffoldState extends ScaffoldState {
bool get _spaceBehindStatusBar =>
(widget as SmoothScaffold).spaceBehindStatusBar == true;

Brightness? get _brightness => (widget as SmoothScaffold).brightness;
Brightness? get _brightness =>
(widget as SmoothScaffold).brightness ??
SmoothBrightnessOverride.of(context)?.brightness;

SystemUiOverlayStyle get _overlayStyle {
switch (_brightness) {
Expand All @@ -130,3 +138,24 @@ class SmoothScaffoldState extends ScaffoldState {
}
}
}

/// Class allowing to override the default [Brightness] of
/// a [SmoothScaffold].
class SmoothBrightnessOverride extends InheritedWidget {
const SmoothBrightnessOverride({
required Widget child,
Key? key,
this.brightness,
}) : super(key: key, child: child);

final Brightness? brightness;

@override
bool updateShouldNotify(SmoothBrightnessOverride oldWidget) =>
brightness != oldWidget.brightness;

static SmoothBrightnessOverride? of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<SmoothBrightnessOverride>();
}
}

0 comments on commit e8c97e4

Please sign in to comment.