✨ iOS check in widget
This commit is contained in:
@@ -20,6 +20,7 @@ import 'package:island/pods/userinfo.dart';
|
||||
import 'package:island/pods/websocket.dart';
|
||||
import 'package:island/route.dart';
|
||||
import 'package:island/services/notify.dart';
|
||||
import 'package:island/services/widget_sync_service.dart';
|
||||
import 'package:island/services/timezone.dart';
|
||||
import 'package:island/widgets/alert.dart';
|
||||
import 'package:island/widgets/app_scaffold.dart';
|
||||
@@ -282,6 +283,11 @@ class IslandApp extends HookConsumerWidget {
|
||||
ref.listen(websocketStateProvider, (_, state) {
|
||||
talker.info('[WebSocket] $state');
|
||||
});
|
||||
ref.listen(userInfoProvider, (_, user) {
|
||||
if (user.value != null) {
|
||||
WidgetSyncService().syncToWidget();
|
||||
}
|
||||
});
|
||||
Future(() {
|
||||
userNotifier.fetchUser().then((_) {
|
||||
final user = ref.watch(userInfoProvider);
|
||||
|
||||
24
lib/services/widget_sync_service.dart
Normal file
24
lib/services/widget_sync_service.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class WidgetSyncService {
|
||||
static const _channel = MethodChannel('dev.solsynth.solian/widget');
|
||||
static final _instance = WidgetSyncService._internal();
|
||||
|
||||
factory WidgetSyncService() => _instance;
|
||||
|
||||
WidgetSyncService._internal();
|
||||
|
||||
bool get _isSupported => !kIsWeb && (Platform.isAndroid || Platform.isIOS);
|
||||
|
||||
Future<void> syncToWidget() async {
|
||||
if (!_isSupported) return;
|
||||
|
||||
try {
|
||||
await _channel.invokeMethod('syncToWidget');
|
||||
} catch (e) {
|
||||
debugPrint('Failed to sync to widget: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,7 @@ class AppWrapper extends HookConsumerWidget {
|
||||
final router = ref.read(routerProvider);
|
||||
if (uri.queryParameters.isNotEmpty) {
|
||||
path = Uri.parse(
|
||||
path,
|
||||
path == '/dashboard' ? '/' : path,
|
||||
).replace(queryParameters: uri.queryParameters).toString();
|
||||
}
|
||||
router.push(path);
|
||||
|
||||
Reference in New Issue
Block a user