diff --git a/lib/main.dart b/lib/main.dart index bad11c0..d86ecf5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -37,7 +37,6 @@ import 'package:flutter_web_plugins/url_strategy.dart' show usePathUrlStrategy; import 'package:surface/widgets/dialog.dart'; import 'package:surface/widgets/version_label.dart'; - void main() async { WidgetsFlutterBinding.ensureInitialized(); await EasyLocalization.ensureInitialized(); @@ -94,7 +93,7 @@ class SolianApp extends StatelessWidget { Provider(create: (ctx) => HomeWidgetProvider(ctx)), // Data layer - Provider(create: (_) => SnNetworkProvider()), + Provider(create: (ctx) => SnNetworkProvider(ctx)), Provider(create: (ctx) => UserDirectoryProvider(ctx)), Provider(create: (ctx) => SnAttachmentProvider(ctx)), Provider(create: (ctx) => SnPostContentProvider(ctx)), @@ -206,7 +205,10 @@ class _AppSplashScreenState extends State<_AppSplashScreen> { mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - Image.asset("assets/icon/icon.png", width: 64, height: 64), + if (MediaQuery.of(context).platformBrightness == Brightness.dark) + Image.asset("assets/icon/icon-dark.png", width: 64, height: 64) + else + Image.asset("assets/icon/icon.png", width: 64, height: 64), const Gap(6), LinearProgressIndicator( backgroundColor: Theme.of(context).colorScheme.surfaceContainer, diff --git a/lib/providers/sn_network.dart b/lib/providers/sn_network.dart index b8eb034..7436a48 100644 --- a/lib/providers/sn_network.dart +++ b/lib/providers/sn_network.dart @@ -6,9 +6,12 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:dio_smart_retry/dio_smart_retry.dart'; import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:device_info_plus/device_info_plus.dart'; +import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:surface/providers/widget.dart'; import 'package:synchronized/synchronized.dart'; const kAtkStoreKey = 'nex_user_atk'; @@ -26,10 +29,13 @@ class SnNetworkProvider { late final Dio client; late final SharedPreferences _prefs; + late final HomeWidgetProvider _home; String? _userAgent; - SnNetworkProvider() { + SnNetworkProvider(BuildContext context) { + _home = context.read(); + client = Dio(); client.interceptors.add(RetryInterceptor( @@ -63,6 +69,8 @@ class SnNetworkProvider { SharedPreferences.getInstance().then((prefs) { _prefs = prefs; client.options.baseUrl = _prefs.getString(kNetworkServerStoreKey) ?? kNetworkServerDefault; + if (!context.mounted) return; + _home.saveWidgetData("server_url", client.options.baseUrl); }); } @@ -190,5 +198,6 @@ class SnNetworkProvider { void setBaseUrl(String url) { client.options.baseUrl = url; + _home.saveWidgetData("server_url", client.options.baseUrl); } } diff --git a/pubspec.yaml b/pubspec.yaml index ec0a2b1..3b880da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -138,6 +138,7 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - assets/icon/icon.png + - assets/icon/icon-dark.png - assets/icon/icon-light-radius.png - assets/translations/