Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Fix crash, goldens, demo status bar icon color #936

Merged
merged 15 commits into from
Apr 27, 2023
14 changes: 12 additions & 2 deletions lib/feature_discovery/feature_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

import 'package:gallery/feature_discovery/animation.dart';
import 'package:gallery/feature_discovery/overlay.dart';
import 'package:get_storage/get_storage.dart';

const _featureHighlightShownKey = 'feature_highlight_shown';

/// [Widget] to enforce a global lock system for [FeatureDiscovery] widgets.
///
Expand Down Expand Up @@ -269,7 +271,15 @@ class _FeatureDiscoveryState extends State<FeatureDiscovery>

initAnimationControllers();
initAnimations();
showOverlay = widget.showOverlay;

final localStorage = GetStorage();
final featureHiglightShown =
localStorage.read<bool>(_featureHighlightShownKey) ?? false;
localStorage.write(_featureHighlightShownKey, true);
showOverlay = widget.showOverlay && !featureHiglightShown;
if (showOverlay) {
localStorage.write(_featureHighlightShownKey, true);
}
}

void initAnimationControllers() {
Expand Down
8 changes: 5 additions & 3 deletions lib/feature_discovery/overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:math';

import 'package:flutter/material.dart';

import 'package:gallery/feature_discovery/animation.dart';

const contentHeight = 80.0;
Expand Down Expand Up @@ -311,6 +310,7 @@ class TapTarget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return Positioned(
left: center.dx,
top: center.dy,
Expand All @@ -323,8 +323,10 @@ class TapTarget extends StatelessWidget {
child: Container(
height: radius * 2,
width: radius * 2,
decoration: const BoxDecoration(
color: Colors.white,
decoration: BoxDecoration(
color: theme.brightness == Brightness.dark
? theme.colorScheme.primary
: Colors.white,
shape: BoxShape.circle,
),
child: child,
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:gallery/pages/backdrop.dart';
import 'package:gallery/pages/splash.dart';
import 'package:gallery/routes.dart';
import 'package:gallery/themes/gallery_theme_data.dart';
import 'package:get_storage/get_storage.dart';
import 'package:google_fonts/google_fonts.dart';

import 'firebase_options.dart';
Expand All @@ -25,6 +26,7 @@ export 'package:gallery/data/demos.dart' show pumpDeferredLibraries;

void main() async {
GoogleFonts.config.allowRuntimeFetching = false;
await GetStorage.init();

if (defaultTargetPlatform != TargetPlatform.linux &&
defaultTargetPlatform != TargetPlatform.windows) {
Expand Down
12 changes: 4 additions & 8 deletions lib/pages/backdrop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,10 @@ class _BackdropState extends State<Backdrop> with TickerProviderStateMixin {
),
),
],
Positioned(
top: 12,
right: 0,
child: _SettingsIcon(
animationController: _iconController,
toggleSettings: _toggleSettings,
isSettingsOpenNotifier: _isSettingsOpenNotifier,
),
_SettingsIcon(
animationController: _iconController,
toggleSettings: _toggleSettings,
isSettingsOpenNotifier: _isSettingsOpenNotifier,
),
],
),
Expand Down
47 changes: 6 additions & 41 deletions lib/pages/demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' show Platform;

import 'package:dual_screen/dual_screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/gallery_localizations.dart';
Expand All @@ -21,11 +18,8 @@ import 'package:gallery/pages/splash.dart';
import 'package:gallery/themes/gallery_theme_data.dart';
import 'package:gallery/themes/material_demo_theme_data.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher_string.dart';

const _demoViewedCountKey = 'demoViewedCountKey';

enum _DemoState {
normal,
options,
Expand Down Expand Up @@ -94,8 +88,6 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>
final RestorableInt _configIndex = RestorableInt(0);

bool? _isDesktop;
bool _showFeatureHighlight = true;
late int _demoViewedCount;

late AnimationController _codeBackgroundColorController;

Expand All @@ -114,32 +106,13 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>

bool get _hasOptions => widget.demo.configurations.length > 1;

bool get _isSupportedSharedPreferencesPlatform =>
!kIsWeb && (Platform.isAndroid || Platform.isIOS);

// Only show the feature highlight on Android/iOS, in mobile layout, non-test
// mode, and only on the first and fourth time the demo page is viewed.
bool _showFeatureHighlightForPlatform(BuildContext context) {
return _showFeatureHighlight &&
_isSupportedSharedPreferencesPlatform &&
!isDisplayDesktop(context) &&
!GalleryOptions.of(context).isTestMode &&
(_demoViewedCount == 0 || _demoViewedCount == 3);
}

@override
void initState() {
super.initState();
_codeBackgroundColorController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
);
SharedPreferences.getInstance().then((preferences) {
setState(() {
_demoViewedCount = preferences.getInt(_demoViewedCountKey) ?? 0;
preferences.setInt(_demoViewedCountKey, _demoViewedCount + 1);
});
});
}

@override
Expand Down Expand Up @@ -245,8 +218,10 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>
final appBarPadding = isDesktop ? 20.0 : 0.0;
final currentDemoState = _DemoState.values[_demoStateIndex.value];
final localizations = GalleryLocalizations.of(context)!;
final options = GalleryOptions.of(context);

final appBar = AppBar(
systemOverlayStyle: options.resolvedSystemUiOverlayStyle(),
backgroundColor: Colors.transparent,
leading: Padding(
padding: EdgeInsetsDirectional.only(start: appBarPadding),
Expand All @@ -265,22 +240,12 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>
icon: FeatureDiscovery(
title: localizations.demoOptionsFeatureTitle,
description: localizations.demoOptionsFeatureDescription,
showOverlay: _showFeatureHighlightForPlatform(context),
showOverlay: !isDisplayDesktop(context) && !options.isTestMode,
color: colorScheme.primary,
onDismiss: () {
setState(() {
_showFeatureHighlight = false;
});
},
onTap: () {
setState(() {
_showFeatureHighlight = false;
});
},
onTap: () => _handleTap(_DemoState.options),
child: Icon(
Icons.tune,
color: currentDemoState == _DemoState.options ||
_showFeatureHighlightForPlatform(context)
color: currentDemoState == _DemoState.options
? selectedIconColor
: iconColor,
),
Expand Down Expand Up @@ -361,7 +326,7 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>
break;
case _DemoState.code:
final codeTheme = GoogleFonts.robotoMono(
fontSize: 12 * GalleryOptions.of(context).textScaleFactor(context),
fontSize: 12 * options.textScaleFactor(context),
);
section = CodeStyle(
baseStyle: codeTheme.copyWith(color: const Color(0xFFFAFBFB)),
Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import firebase_core
import firebase_crashlytics
import package_info_plus
import path_provider_foundation
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseCrashlyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCrashlyticsPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
7 changes: 0 additions & 7 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ PODS:
- PromisesObjC (2.2.0)
- PromisesSwift (2.2.0):
- PromisesObjC (= 2.2.0)
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- url_launcher_macos (0.0.1):
- FlutterMacOS

Expand All @@ -78,7 +75,6 @@ DEPENDENCIES:
- FlutterMacOS (from `Flutter/ephemeral`)
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

SPEC REPOS:
Expand Down Expand Up @@ -107,8 +103,6 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

Expand All @@ -130,7 +124,6 @@ SPEC CHECKSUMS:
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
PromisesSwift: cf9eb58666a43bbe007302226e510b16c1e10959
shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472
url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
Expand Down
72 changes: 16 additions & 56 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
get:
dependency: transitive
description:
name: get
sha256: "2ba20a47c8f1f233bed775ba2dd0d3ac97b4cf32fc17731b3dfc672b06b0e92a"
url: "https://pub.dev"
source: hosted
version: "4.6.5"
get_storage:
dependency: "direct main"
description:
name: get_storage
sha256: "39db1fffe779d0c22b3a744376e86febe4ade43bf65e06eab5af707dc84185a2"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -575,62 +591,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
sha256: "858aaa72d8f61637d64e776aca82e1c67e6d9ee07979123c5d17115031c1b13b"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "7fa90471a6875d26ad78c7e4a675874b2043874586891128dc5899662c97db46"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "0c1c16c56c9708aa9c361541a6f0e5cc6fc12a3232d866a687a7b7db30032b07"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "9d387433ca65717bbf1be88f4d5bb18f10508917a8fa2fb02e0fd0d7479a9afa"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: fb5cf25c0235df2d0640ac1b1174f6466bd311f621574997ac59018a6664548d
url: "https://pub.dev"
source: hosted
version: "2.2.0"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: "74083203a8eae241e0de4a0d597dbedab3b8fef5563f33cf3c12d7e93c655ca5"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "5e588e2efef56916a3b229c3bfe81e6a525665a454519ca51dbcc4236a274173"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
shelf:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: gallery
description: A resource to help developers evaluate and use Flutter.
repository: https://github.com/flutter/gallery
version: 2.10.0+021000 # See README.md for details on versioning.
version: 2.10.1+021001 # See README.md for details on versioning.

environment:
flutter: ^3.10.0-10.0.pre.17 # Keep relatively close to master channel version
Expand All @@ -23,6 +23,7 @@ dependencies:
firebase_core: ^2.7.0
firebase_crashlytics: ^3.1.1
firebase_performance: ^0.9.0+14
get_storage: ^2.1.1
google_fonts: ^4.0.1
intl: any # An exact version pin will be provided by the Flutter SDK
meta: ^1.7.0
Expand All @@ -31,7 +32,6 @@ dependencies:
provider: ^6.0.2
rally_assets: ^3.0.1
scoped_model: ^2.0.0
shared_preferences: ^2.0.15
shrine_images: ^2.0.1
transparent_image: ^2.0.1
url_launcher: ^6.1.2
Expand Down
5 changes: 0 additions & 5 deletions test_goldens/flutter_test_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'testing/font_loader.dart';

Expand All @@ -21,10 +20,6 @@ Future<void> testExecutable(FutureOr<void> Function() testMain) async {
};

TestWidgetsFlutterBinding.ensureInitialized();
// Disabling the warning because @visibleForTesting doesn't take the testing
// framework into account.
// ignore: invalid_use_of_visible_for_testing_member
SharedPreferences.setMockInitialValues(<String, String>{});
await loadFonts();
await testMain();
}
Binary file modified test_goldens/goldens/demo_desktop_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/demo_desktop_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/demo_mobile_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/demo_mobile_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/home_page_desktop_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/home_page_desktop_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/home_page_mobile_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/home_page_mobile_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/shrine_desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/shrine_mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.