mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-12 08:31:05 +01:00
Same pattern as todo, diet_guard_app, and workout_app: openFirebaseWithGoogle() (google_platform.dart abstracts the plugin's platform-channel dependence), isFirebaseConfigured() reading the stored session rather than the account marker alone, and the settings screen offering "Sign in with Google" ahead of the password form. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdSp6Nbrs9xvsWkCMDN9a1
49 lines
1.6 KiB
Dart
49 lines
1.6 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// In-memory fake for the `flutter_secure_storage` platform channel so tests
|
|
/// never touch the real OS keystore. Install it from a test (or `setUp`) and it
|
|
/// auto-removes on tear down.
|
|
///
|
|
/// Pass [throwing] to simulate a host with no secret service: every call raises
|
|
/// a `PlatformException`, which exercises the plaintext-fallback paths.
|
|
void installFakeSecureStorage({
|
|
Map<String, String>? initial,
|
|
bool throwing = false,
|
|
}) {
|
|
const channel = MethodChannel('plugins.it_nomads.com/flutter_secure_storage');
|
|
final store = <String, String>{...?initial};
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
|
|
Future<Object?>? handler(MethodCall call) async {
|
|
if (throwing) {
|
|
throw PlatformException(code: 'unavailable');
|
|
}
|
|
final args = (call.arguments as Map?) ?? const <Object?, Object?>{};
|
|
final key = args['key'] as String?;
|
|
switch (call.method) {
|
|
case 'read':
|
|
return store[key];
|
|
case 'write':
|
|
store[key!] = args['value']! as String;
|
|
return null;
|
|
case 'delete':
|
|
store.remove(key);
|
|
return null;
|
|
case 'containsKey':
|
|
return store.containsKey(key);
|
|
case 'readAll':
|
|
return Map<String, String>.from(store);
|
|
case 'deleteAll':
|
|
store.clear();
|
|
return null;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
messenger.setMockMethodCallHandler(channel, handler);
|
|
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
|
}
|