refactor: migrate to go_router navigation
This commit is contained in:
194
lib/core/router/app_router.dart
Normal file
194
lib/core/router/app_router.dart
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
import '../providers/app_providers.dart';
|
||||||
|
import '../services/navigation_service.dart';
|
||||||
|
import '../utils/debug_logger.dart';
|
||||||
|
import '../../features/auth/providers/unified_auth_providers.dart';
|
||||||
|
import '../../features/auth/views/authentication_page.dart';
|
||||||
|
import '../../features/auth/views/connect_signin_page.dart';
|
||||||
|
import '../../features/auth/views/server_connection_page.dart';
|
||||||
|
import '../../features/chat/views/chat_page.dart';
|
||||||
|
import '../../features/files/views/workspace_page.dart';
|
||||||
|
import '../../features/navigation/views/splash_launcher_page.dart';
|
||||||
|
import '../../features/profile/views/app_customization_page.dart';
|
||||||
|
import '../../features/profile/views/profile_page.dart';
|
||||||
|
import '../../l10n/app_localizations.dart';
|
||||||
|
import '../models/server_config.dart';
|
||||||
|
|
||||||
|
class RouterNotifier extends ChangeNotifier {
|
||||||
|
RouterNotifier(this.ref) {
|
||||||
|
_subscriptions = [
|
||||||
|
ref.listen<bool>(reviewerModeProvider, _onStateChanged),
|
||||||
|
ref.listen<AsyncValue<ServerConfig?>>(
|
||||||
|
activeServerProvider,
|
||||||
|
_onStateChanged,
|
||||||
|
),
|
||||||
|
ref.listen<AuthNavigationState>(
|
||||||
|
authNavigationStateProvider,
|
||||||
|
_onStateChanged,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
final Ref ref;
|
||||||
|
late final List<ProviderSubscription<dynamic>> _subscriptions;
|
||||||
|
|
||||||
|
void _onStateChanged(dynamic previous, dynamic next) {
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
String? redirect(BuildContext context, GoRouterState state) {
|
||||||
|
final location = state.uri.path.isEmpty ? Routes.splash : state.uri.path;
|
||||||
|
final reviewerMode = ref.read(reviewerModeProvider);
|
||||||
|
final activeServerAsync = ref.read(activeServerProvider);
|
||||||
|
|
||||||
|
if (reviewerMode) {
|
||||||
|
if (location == Routes.chat) return null;
|
||||||
|
return Routes.chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeServerAsync.isLoading) {
|
||||||
|
return location == Routes.splash ? null : Routes.splash;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeServerAsync.hasError) {
|
||||||
|
return location == Routes.serverConnection
|
||||||
|
? null
|
||||||
|
: Routes.serverConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
final activeServer = activeServerAsync.asData?.value;
|
||||||
|
if (activeServer == null) {
|
||||||
|
if (_isAuthLocation(location)) return null;
|
||||||
|
return Routes.serverConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
final authState = ref.read(authNavigationStateProvider);
|
||||||
|
switch (authState) {
|
||||||
|
case AuthNavigationState.loading:
|
||||||
|
return location == Routes.splash ? null : Routes.splash;
|
||||||
|
case AuthNavigationState.needsLogin:
|
||||||
|
case AuthNavigationState.error:
|
||||||
|
if (_isAuthLocation(location)) return null;
|
||||||
|
return Routes.serverConnection;
|
||||||
|
case AuthNavigationState.authenticated:
|
||||||
|
if (_isAuthLocation(location) || location == Routes.splash) {
|
||||||
|
return Routes.chat;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isAuthLocation(String location) {
|
||||||
|
return location == Routes.serverConnection ||
|
||||||
|
location == Routes.login ||
|
||||||
|
location == Routes.authentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
for (final sub in _subscriptions) {
|
||||||
|
sub.close();
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final routerNotifierProvider = Provider<RouterNotifier>((ref) {
|
||||||
|
final notifier = RouterNotifier(ref);
|
||||||
|
ref.onDispose(notifier.dispose);
|
||||||
|
return notifier;
|
||||||
|
});
|
||||||
|
|
||||||
|
final goRouterProvider = Provider<GoRouter>((ref) {
|
||||||
|
final notifier = ref.watch(routerNotifierProvider);
|
||||||
|
|
||||||
|
final routes = <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.splash,
|
||||||
|
name: RouteNames.splash,
|
||||||
|
builder: (context, state) => const SplashLauncherPage(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.chat,
|
||||||
|
name: RouteNames.chat,
|
||||||
|
builder: (context, state) => const ChatPage(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.login,
|
||||||
|
name: RouteNames.login,
|
||||||
|
builder: (context, state) => const ConnectAndSignInPage(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.serverConnection,
|
||||||
|
name: RouteNames.serverConnection,
|
||||||
|
builder: (context, state) => const ServerConnectionPage(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.authentication,
|
||||||
|
name: RouteNames.authentication,
|
||||||
|
builder: (context, state) {
|
||||||
|
final config = state.extra;
|
||||||
|
if (config is! ServerConfig) {
|
||||||
|
return const ServerConnectionPage();
|
||||||
|
}
|
||||||
|
return AuthenticationPage(serverConfig: config);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.profile,
|
||||||
|
name: RouteNames.profile,
|
||||||
|
builder: (context, state) => const ProfilePage(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.appCustomization,
|
||||||
|
name: RouteNames.appCustomization,
|
||||||
|
builder: (context, state) => const AppCustomizationPage(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: Routes.workspace,
|
||||||
|
name: RouteNames.workspace,
|
||||||
|
builder: (context, state) => const WorkspacePage(),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
final router = GoRouter(
|
||||||
|
navigatorKey: NavigationService.navigatorKey,
|
||||||
|
initialLocation: Routes.splash,
|
||||||
|
refreshListenable: notifier,
|
||||||
|
redirect: notifier.redirect,
|
||||||
|
routes: routes,
|
||||||
|
observers: [NavigationLoggingObserver()],
|
||||||
|
errorBuilder: (context, state) {
|
||||||
|
final l10n = AppLocalizations.of(context);
|
||||||
|
final message =
|
||||||
|
l10n?.routeNotFound(state.uri.path) ??
|
||||||
|
'Route not found: ${state.uri.path}';
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(child: Text(message, textAlign: TextAlign.center)),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
NavigationService.attachRouter(router);
|
||||||
|
return router;
|
||||||
|
});
|
||||||
|
|
||||||
|
class NavigationLoggingObserver extends NavigatorObserver {
|
||||||
|
@override
|
||||||
|
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
||||||
|
super.didPush(route, previousRoute);
|
||||||
|
final previous = previousRoute?.settings.name ?? previousRoute?.settings;
|
||||||
|
DebugLogger.navigation(
|
||||||
|
'Pushed: ${route.settings.name ?? route.settings} (from ${previous ?? 'root'})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
||||||
|
super.didPop(route, previousRoute);
|
||||||
|
DebugLogger.navigation('Popped: ${route.settings.name ?? route.settings}');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,67 +1,70 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
// ThemedDialogs handles theming; no direct use of extensions here
|
import 'package:go_router/go_router.dart';
|
||||||
import '../../features/auth/views/connect_signin_page.dart';
|
|
||||||
import '../../features/chat/views/chat_page.dart';
|
|
||||||
import '../../features/files/views/workspace_page.dart';
|
|
||||||
import '../../features/profile/views/profile_page.dart';
|
|
||||||
import '../../shared/widgets/themed_dialogs.dart';
|
import '../../shared/widgets/themed_dialogs.dart';
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
|
||||||
|
|
||||||
/// Service for handling navigation throughout the app
|
/// Service for handling navigation throughout the app.
|
||||||
|
///
|
||||||
|
/// With GoRouter in place, this class mostly provides convenient wrappers
|
||||||
|
/// around the global router so existing callers can trigger navigation
|
||||||
|
/// without directly depending on BuildContext.
|
||||||
class NavigationService {
|
class NavigationService {
|
||||||
static final GlobalKey<NavigatorState> navigatorKey =
|
static final GlobalKey<NavigatorState> navigatorKey =
|
||||||
GlobalKey<NavigatorState>();
|
GlobalKey<NavigatorState>(debugLabel: 'rootNavigator');
|
||||||
|
|
||||||
|
static GoRouter? _router;
|
||||||
|
|
||||||
|
static GoRouter get router {
|
||||||
|
final router = _router;
|
||||||
|
if (router == null) {
|
||||||
|
throw StateError('GoRouter has not been attached to NavigationService.');
|
||||||
|
}
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void attachRouter(GoRouter router) {
|
||||||
|
_router = router;
|
||||||
|
}
|
||||||
|
|
||||||
static NavigatorState? get navigator => navigatorKey.currentState;
|
static NavigatorState? get navigator => navigatorKey.currentState;
|
||||||
static BuildContext? get context => navigatorKey.currentContext;
|
static BuildContext? get context => navigatorKey.currentContext;
|
||||||
|
|
||||||
static final List<String> _navigationStack = [];
|
/// The current location reported by GoRouter.
|
||||||
static String? _currentRoute;
|
static String? get currentRoute {
|
||||||
|
final router = _router;
|
||||||
|
if (router == null) return null;
|
||||||
|
return router.routeInformationProvider.value.uri.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get current route
|
/// Navigate to a specific route path.
|
||||||
static String? get currentRoute => _currentRoute;
|
|
||||||
|
|
||||||
/// Get navigation stack
|
|
||||||
static List<String> get navigationStack =>
|
|
||||||
List.unmodifiable(_navigationStack);
|
|
||||||
|
|
||||||
/// Navigate to a specific route
|
|
||||||
static Future<void> navigateTo(String routeName) async {
|
static Future<void> navigateTo(String routeName) async {
|
||||||
if (_currentRoute != routeName) {
|
final router = _router;
|
||||||
_navigationStack.add(routeName);
|
if (router == null) return;
|
||||||
_currentRoute = routeName;
|
router.go(routeName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Navigate back with optional result
|
/// Navigate back with an optional result payload.
|
||||||
static void goBack<T>([T? result]) {
|
static void goBack<T>([T? result]) {
|
||||||
if (navigator?.canPop() == true) {
|
final router = _router;
|
||||||
if (_navigationStack.isNotEmpty) {
|
if (router?.canPop() == true) {
|
||||||
_navigationStack.removeLast();
|
router!.pop(result);
|
||||||
}
|
|
||||||
_currentRoute = _navigationStack.isNotEmpty
|
|
||||||
? _navigationStack.last
|
|
||||||
: null;
|
|
||||||
navigator?.pop<T>(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if can navigate back
|
/// Check whether the router can pop the current route.
|
||||||
static bool canGoBack() {
|
static bool canGoBack() => _router?.canPop() ?? false;
|
||||||
return navigator?.canPop() == true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show confirmation dialog before navigation
|
/// Show confirmation dialog before navigation.
|
||||||
static Future<bool> confirmNavigation({
|
static Future<bool> confirmNavigation({
|
||||||
required String title,
|
required String title,
|
||||||
required String message,
|
required String message,
|
||||||
String confirmText = 'Continue',
|
String confirmText = 'Continue',
|
||||||
String cancelText = 'Cancel',
|
String cancelText = 'Cancel',
|
||||||
}) async {
|
}) async {
|
||||||
if (context == null) return false;
|
final ctx = context;
|
||||||
|
if (ctx == null) return false;
|
||||||
|
|
||||||
final result = await ThemedDialogs.confirm(
|
final result = await ThemedDialogs.confirm(
|
||||||
context!,
|
ctx,
|
||||||
title: title,
|
title: title,
|
||||||
message: message,
|
message: message,
|
||||||
confirmText: confirmText,
|
confirmText: confirmText,
|
||||||
@@ -72,95 +75,40 @@ class NavigationService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Navigate to chat
|
static Future<void> navigateToChat() => navigateTo(Routes.chat);
|
||||||
static Future<void> navigateToChat() {
|
static Future<void> navigateToLogin() => navigateTo(Routes.serverConnection);
|
||||||
return navigateTo(Routes.chat);
|
static Future<void> navigateToProfile() => navigateTo(Routes.profile);
|
||||||
}
|
static Future<void> navigateToServerConnection() =>
|
||||||
|
navigateTo(Routes.serverConnection);
|
||||||
|
|
||||||
/// Navigate to login
|
/// Clear navigation history. With GoRouter this becomes a simple go call.
|
||||||
static Future<void> navigateToLogin() {
|
|
||||||
return navigateTo(Routes.login);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Navigate to profile
|
|
||||||
static Future<void> navigateToProfile() {
|
|
||||||
return navigateTo(Routes.profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Navigate to server connection
|
|
||||||
static Future<void> navigateToServerConnection() {
|
|
||||||
return navigateTo(Routes.serverConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chats list is now provided as a left drawer in ChatPage
|
|
||||||
|
|
||||||
/// Clear navigation stack (useful for logout)
|
|
||||||
static void clearNavigationStack() {
|
static void clearNavigationStack() {
|
||||||
_navigationStack.clear();
|
final router = _router;
|
||||||
_currentRoute = null;
|
if (router == null) return;
|
||||||
}
|
router.go(Routes.serverConnection);
|
||||||
|
|
||||||
/// Set current route (useful for initial app state)
|
|
||||||
static void setCurrentRoute(String routeName) {
|
|
||||||
_currentRoute = routeName;
|
|
||||||
if (!_navigationStack.contains(routeName)) {
|
|
||||||
_navigationStack.add(routeName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate routes
|
/// Route path definitions used across the app.
|
||||||
static Route<dynamic>? generateRoute(RouteSettings settings) {
|
|
||||||
Widget page;
|
|
||||||
|
|
||||||
switch (settings.name) {
|
|
||||||
// Removed tabbed main navigation
|
|
||||||
|
|
||||||
case Routes.chat:
|
|
||||||
page = const ChatPage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Routes.login:
|
|
||||||
page = const ConnectAndSignInPage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Routes.profile:
|
|
||||||
page = const ProfilePage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Routes.serverConnection:
|
|
||||||
page = const ConnectAndSignInPage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Routes.workspace:
|
|
||||||
page = const WorkspacePage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
// chats list route removed (replaced by drawer)
|
|
||||||
|
|
||||||
// Removed navigation drawer route
|
|
||||||
|
|
||||||
default:
|
|
||||||
page = Builder(
|
|
||||||
builder: (context) => Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!
|
|
||||||
.routeNotFound(settings.name ?? ''),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return MaterialPageRoute(builder: (_) => page, settings: settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Route names
|
|
||||||
class Routes {
|
class Routes {
|
||||||
|
static const String splash = '/splash';
|
||||||
static const String chat = '/chat';
|
static const String chat = '/chat';
|
||||||
static const String login = '/login';
|
static const String login = '/login';
|
||||||
static const String profile = '/profile';
|
|
||||||
static const String serverConnection = '/server-connection';
|
static const String serverConnection = '/server-connection';
|
||||||
|
static const String authentication = '/authentication';
|
||||||
|
static const String profile = '/profile';
|
||||||
|
static const String appCustomization = '/profile/customization';
|
||||||
static const String workspace = '/workspace';
|
static const String workspace = '/workspace';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Friendly names for GoRouter routes to support context.pushNamed.
|
||||||
|
class RouteNames {
|
||||||
|
static const String splash = 'splash';
|
||||||
|
static const String chat = 'chat';
|
||||||
|
static const String login = 'login';
|
||||||
|
static const String serverConnection = 'server-connection';
|
||||||
|
static const String authentication = 'authentication';
|
||||||
|
static const String profile = 'profile';
|
||||||
|
static const String appCustomization = 'app-customization';
|
||||||
|
static const String workspace = 'workspace';
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
import 'package:conduit/l10n/app_localizations.dart';
|
||||||
import '../../shared/theme/theme_extensions.dart';
|
import '../../shared/theme/theme_extensions.dart';
|
||||||
|
import 'navigation_service.dart';
|
||||||
|
|
||||||
/// User-friendly error messages and recovery actions
|
/// User-friendly error messages and recovery actions
|
||||||
class UserFriendlyErrorHandler {
|
class UserFriendlyErrorHandler {
|
||||||
@@ -483,7 +484,7 @@ class ErrorCard extends StatelessWidget {
|
|||||||
break;
|
break;
|
||||||
case ErrorActionType.signIn:
|
case ErrorActionType.signIn:
|
||||||
// Navigate to sign in page
|
// Navigate to sign in page
|
||||||
Navigator.of(context).pushReplacementNamed('/login');
|
NavigationService.navigateToServerConnection();
|
||||||
break;
|
break;
|
||||||
case ErrorActionType.openSettings:
|
case ErrorActionType.openSettings:
|
||||||
// Open app settings - would need platform-specific implementation
|
// Open app settings - would need platform-specific implementation
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_animate/flutter_animate.dart';
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../../core/models/server_config.dart';
|
import '../../../core/models/server_config.dart';
|
||||||
import '../../../core/providers/app_providers.dart';
|
import '../../../core/providers/app_providers.dart';
|
||||||
@@ -136,10 +137,7 @@ class _AuthenticationPageState extends ConsumerState<AuthenticationPage> {
|
|||||||
|
|
||||||
DebugLogger.auth('Navigating to chat page');
|
DebugLogger.auth('Navigating to chat page');
|
||||||
// Navigate directly to chat page on successful authentication
|
// Navigate directly to chat page on successful authentication
|
||||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
context.go(Routes.chat);
|
||||||
Routes.chat,
|
|
||||||
(route) => false, // Remove all previous routes
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
import '../../../core/widgets/error_boundary.dart';
|
|
||||||
import '../../../shared/theme/theme_extensions.dart';
|
|
||||||
import '../../../shared/widgets/conduit_components.dart';
|
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
|
||||||
import 'server_connection_page.dart';
|
import 'server_connection_page.dart';
|
||||||
|
|
||||||
/// Entry point for the connection and sign-in flow
|
/// Entry point for the connection and sign-in flow.
|
||||||
/// Redirects to the mobile-first two-step process
|
/// We now forward directly to the server connection experience.
|
||||||
class ConnectAndSignInPage extends ConsumerWidget {
|
class ConnectAndSignInPage extends ConsumerWidget {
|
||||||
const ConnectAndSignInPage({super.key});
|
const ConnectAndSignInPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
// Directly navigate to the new mobile-first server connection page
|
return const ServerConnectionPage();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
Navigator.of(context).pushReplacement(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const ServerConnectionPage(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Show a simple loading state while transitioning
|
|
||||||
return ErrorBoundary(
|
|
||||||
child: Scaffold(
|
|
||||||
backgroundColor: context.conduitTheme.surfaceBackground,
|
|
||||||
body: Center(
|
|
||||||
child: ConduitLoadingIndicator(
|
|
||||||
message: AppLocalizations.of(context)!.loadingContent,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_animate/flutter_animate.dart';
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
import 'package:conduit/l10n/app_localizations.dart';
|
||||||
@@ -12,12 +13,11 @@ import '../../../core/models/server_config.dart';
|
|||||||
import '../../../core/providers/app_providers.dart';
|
import '../../../core/providers/app_providers.dart';
|
||||||
import '../../../core/services/api_service.dart';
|
import '../../../core/services/api_service.dart';
|
||||||
import '../../../core/services/input_validation_service.dart';
|
import '../../../core/services/input_validation_service.dart';
|
||||||
|
import '../../../core/services/navigation_service.dart';
|
||||||
import '../../../core/widgets/error_boundary.dart';
|
import '../../../core/widgets/error_boundary.dart';
|
||||||
import '../../../shared/services/brand_service.dart';
|
import '../../../shared/services/brand_service.dart';
|
||||||
import '../../../shared/theme/theme_extensions.dart';
|
import '../../../shared/theme/theme_extensions.dart';
|
||||||
import '../../../shared/widgets/conduit_components.dart';
|
import '../../../shared/widgets/conduit_components.dart';
|
||||||
import '../../chat/views/chat_page.dart';
|
|
||||||
import 'authentication_page.dart';
|
|
||||||
|
|
||||||
class ServerConnectionPage extends ConsumerStatefulWidget {
|
class ServerConnectionPage extends ConsumerStatefulWidget {
|
||||||
const ServerConnectionPage({super.key});
|
const ServerConnectionPage({super.key});
|
||||||
@@ -88,11 +88,7 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
|
|
||||||
// Navigate to authentication page
|
// Navigate to authentication page
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).push(
|
context.pushNamed(RouteNames.authentication, extra: tempConfig);
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => AuthenticationPage(serverConfig: tempConfig),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -208,7 +204,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
return cleanError;
|
return cleanError;
|
||||||
} else if (error.contains('Invalid IP address format')) {
|
} else if (error.contains('Invalid IP address format')) {
|
||||||
return cleanError;
|
return cleanError;
|
||||||
} else if (error.contains('This does not appear to be an Open-WebUI server')) {
|
} else if (error.contains(
|
||||||
|
'This does not appear to be an Open-WebUI server',
|
||||||
|
)) {
|
||||||
return AppLocalizations.of(context)!.serverNotOpenWebUI;
|
return AppLocalizations.of(context)!.serverNotOpenWebUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,8 +338,12 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
gradient: RadialGradient(
|
gradient: RadialGradient(
|
||||||
colors: [
|
colors: [
|
||||||
context.conduitTheme.buttonPrimary.withValues(alpha: 0.12),
|
context.conduitTheme.buttonPrimary.withValues(
|
||||||
context.conduitTheme.buttonPrimary.withValues(alpha: 0.06),
|
alpha: 0.12,
|
||||||
|
),
|
||||||
|
context.conduitTheme.buttonPrimary.withValues(
|
||||||
|
alpha: 0.06,
|
||||||
|
),
|
||||||
Colors.transparent,
|
Colors.transparent,
|
||||||
],
|
],
|
||||||
stops: const [0.0, 0.7, 1.0],
|
stops: const [0.0, 0.7, 1.0],
|
||||||
@@ -361,7 +363,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: ConduitBadge(
|
child: ConduitBadge(
|
||||||
text: AppLocalizations.of(context)!.demoBadge,
|
text: AppLocalizations.of(context)!.demoBadge,
|
||||||
backgroundColor: context.conduitTheme.warning.withValues(alpha: 0.15),
|
backgroundColor: context.conduitTheme.warning.withValues(
|
||||||
|
alpha: 0.15,
|
||||||
|
),
|
||||||
textColor: context.conduitTheme.warning,
|
textColor: context.conduitTheme.warning,
|
||||||
isCompact: true,
|
isCompact: true,
|
||||||
),
|
),
|
||||||
@@ -448,11 +452,7 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
text: AppLocalizations.of(context)!.enterDemo,
|
text: AppLocalizations.of(context)!.enterDemo,
|
||||||
icon: Platform.isIOS ? CupertinoIcons.play_fill : Icons.play_arrow,
|
icon: Platform.isIOS ? CupertinoIcons.play_fill : Icons.play_arrow,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).push(
|
context.go(Routes.chat);
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const ChatPage(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
isSecondary: true,
|
isSecondary: true,
|
||||||
isFullWidth: true,
|
isFullWidth: true,
|
||||||
@@ -475,7 +475,8 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
controller: _urlController,
|
controller: _urlController,
|
||||||
validator: InputValidationService.combine([
|
validator: InputValidationService.combine([
|
||||||
InputValidationService.validateRequired,
|
InputValidationService.validateRequired,
|
||||||
(value) => InputValidationService.validateUrl(value, required: true),
|
(value) =>
|
||||||
|
InputValidationService.validateUrl(value, required: true),
|
||||||
]),
|
]),
|
||||||
keyboardType: TextInputType.url,
|
keyboardType: TextInputType.url,
|
||||||
semanticLabel: AppLocalizations.of(context)!.enterServerUrlSemantic,
|
semanticLabel: AppLocalizations.of(context)!.enterServerUrlSemantic,
|
||||||
@@ -516,7 +517,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () => setState(() => _showAdvancedSettings = !_showAdvancedSettings),
|
onTap: () => setState(
|
||||||
|
() => _showAdvancedSettings = !_showAdvancedSettings,
|
||||||
|
),
|
||||||
borderRadius: BorderRadius.circular(AppBorderRadius.button),
|
borderRadius: BorderRadius.circular(AppBorderRadius.button),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: Spacing.sm),
|
padding: const EdgeInsets.symmetric(vertical: Spacing.sm),
|
||||||
@@ -552,7 +555,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
duration: AnimationDuration.microInteraction,
|
duration: AnimationDuration.microInteraction,
|
||||||
turns: _showAdvancedSettings ? 0.5 : 0,
|
turns: _showAdvancedSettings ? 0.5 : 0,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Platform.isIOS ? CupertinoIcons.chevron_down : Icons.expand_more,
|
Platform.isIOS
|
||||||
|
? CupertinoIcons.chevron_down
|
||||||
|
: Icons.expand_more,
|
||||||
color: context.conduitTheme.iconSecondary,
|
color: context.conduitTheme.iconSecondary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -563,7 +568,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
AnimatedSize(
|
AnimatedSize(
|
||||||
duration: AnimationDuration.microInteraction,
|
duration: AnimationDuration.microInteraction,
|
||||||
curve: Curves.easeInOutCubic,
|
curve: Curves.easeInOutCubic,
|
||||||
child: _showAdvancedSettings ? _buildAdvancedSettingsContent() : const SizedBox.shrink(),
|
child: _showAdvancedSettings
|
||||||
|
? _buildAdvancedSettingsContent()
|
||||||
|
: const SizedBox.shrink(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -679,8 +686,8 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
fit: FlexFit.loose,
|
fit: FlexFit.loose,
|
||||||
child: ConduitBadge(
|
child: ConduitBadge(
|
||||||
text: entry.key,
|
text: entry.key,
|
||||||
backgroundColor:
|
backgroundColor: context.conduitTheme.buttonPrimary
|
||||||
context.conduitTheme.buttonPrimary.withValues(alpha: 0.1),
|
.withValues(alpha: 0.1),
|
||||||
textColor: context.conduitTheme.buttonPrimary,
|
textColor: context.conduitTheme.buttonPrimary,
|
||||||
isCompact: true,
|
isCompact: true,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
@@ -704,7 +711,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
icon: Platform.isIOS ? CupertinoIcons.xmark : Icons.close,
|
icon: Platform.isIOS ? CupertinoIcons.xmark : Icons.close,
|
||||||
onPressed: () => _removeCustomHeader(entry.key),
|
onPressed: () => _removeCustomHeader(entry.key),
|
||||||
tooltip: AppLocalizations.of(context)!.removeHeader,
|
tooltip: AppLocalizations.of(context)!.removeHeader,
|
||||||
backgroundColor: context.conduitTheme.error.withValues(alpha: 0.1),
|
backgroundColor: context.conduitTheme.error.withValues(
|
||||||
|
alpha: 0.1,
|
||||||
|
),
|
||||||
iconColor: context.conduitTheme.error,
|
iconColor: context.conduitTheme.error,
|
||||||
isCompact: true,
|
isCompact: true,
|
||||||
),
|
),
|
||||||
@@ -718,13 +727,16 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
Widget _buildConnectButton() {
|
Widget _buildConnectButton() {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(top: Spacing.lg),
|
padding: const EdgeInsets.only(top: Spacing.lg),
|
||||||
child: ConduitButton(
|
child:
|
||||||
|
ConduitButton(
|
||||||
text: _isConnecting
|
text: _isConnecting
|
||||||
? AppLocalizations.of(context)!.connecting
|
? AppLocalizations.of(context)!.connecting
|
||||||
: AppLocalizations.of(context)!.connectToServerButton,
|
: AppLocalizations.of(context)!.connectToServerButton,
|
||||||
icon: _isConnecting
|
icon: _isConnecting
|
||||||
? null
|
? null
|
||||||
: (Platform.isIOS ? CupertinoIcons.arrow_right : Icons.arrow_forward),
|
: (Platform.isIOS
|
||||||
|
? CupertinoIcons.arrow_right
|
||||||
|
: Icons.arrow_forward),
|
||||||
onPressed: _isConnecting ? null : _connectToServer,
|
onPressed: _isConnecting ? null : _connectToServer,
|
||||||
isLoading: _isConnecting,
|
isLoading: _isConnecting,
|
||||||
isFullWidth: true,
|
isFullWidth: true,
|
||||||
@@ -826,9 +838,18 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
// Check for reserved headers that should not be overridden
|
// Check for reserved headers that should not be overridden
|
||||||
final lowerKey = key.toLowerCase();
|
final lowerKey = key.toLowerCase();
|
||||||
final reservedHeaders = {
|
final reservedHeaders = {
|
||||||
'authorization', 'content-type', 'content-length', 'host',
|
'authorization',
|
||||||
'user-agent', 'accept', 'accept-encoding', 'connection',
|
'content-type',
|
||||||
'transfer-encoding', 'upgrade', 'via', 'warning'
|
'content-length',
|
||||||
|
'host',
|
||||||
|
'user-agent',
|
||||||
|
'accept',
|
||||||
|
'accept-encoding',
|
||||||
|
'connection',
|
||||||
|
'transfer-encoding',
|
||||||
|
'upgrade',
|
||||||
|
'via',
|
||||||
|
'warning',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (reservedHeaders.contains(lowerKey)) {
|
if (reservedHeaders.contains(lowerKey)) {
|
||||||
@@ -840,7 +861,9 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
|
|
||||||
String? _validateHeaderValue(String value) {
|
String? _validateHeaderValue(String value) {
|
||||||
if (value.isEmpty) return AppLocalizations.of(context)!.headerValueEmpty;
|
if (value.isEmpty) return AppLocalizations.of(context)!.headerValueEmpty;
|
||||||
if (value.length > 1024) return AppLocalizations.of(context)!.headerValueTooLong;
|
if (value.length > 1024) {
|
||||||
|
return AppLocalizations.of(context)!.headerValueTooLong;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for valid characters (no control characters except tab)
|
// Check for valid characters (no control characters except tab)
|
||||||
for (int i = 0; i < value.length; i++) {
|
for (int i = 0; i < value.length; i++) {
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../../core/providers/app_providers.dart';
|
import '../../../core/providers/app_providers.dart';
|
||||||
import '../../../shared/theme/theme_extensions.dart';
|
import '../../../shared/theme/theme_extensions.dart';
|
||||||
import '../../chat/providers/chat_providers.dart' as chat;
|
import '../../chat/providers/chat_providers.dart' as chat;
|
||||||
// import '../../files/views/files_page.dart';
|
// import '../../files/views/files_page.dart';
|
||||||
import '../../profile/views/profile_page.dart';
|
|
||||||
import '../../../shared/utils/ui_utils.dart';
|
import '../../../shared/utils/ui_utils.dart';
|
||||||
|
import '../../../core/services/navigation_service.dart';
|
||||||
import '../../../shared/widgets/themed_dialogs.dart';
|
import '../../../shared/widgets/themed_dialogs.dart';
|
||||||
import '../../../core/auth/auth_state_manager.dart';
|
import '../../../core/auth/auth_state_manager.dart';
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
import 'package:conduit/l10n/app_localizations.dart';
|
||||||
@@ -1190,11 +1191,12 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
|
|||||||
container.read(activeConversationProvider.notifier).set(full);
|
container.read(activeConversationProvider.notifier).set(full);
|
||||||
} else {
|
} else {
|
||||||
// Fallback: use the lightweight item to update the active conversation
|
// Fallback: use the lightweight item to update the active conversation
|
||||||
container.read(activeConversationProvider.notifier).set(
|
container
|
||||||
|
.read(activeConversationProvider.notifier)
|
||||||
|
.set(
|
||||||
(await container.read(
|
(await container.read(
|
||||||
conversationsProvider.future,
|
conversationsProvider.future,
|
||||||
))
|
)).firstWhere((c) => c.id == id),
|
||||||
.firstWhere((c) => c.id == id),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1292,9 +1294,7 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
|
|||||||
tooltip: AppLocalizations.of(context)!.manage,
|
tooltip: AppLocalizations.of(context)!.manage,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).maybePop();
|
Navigator.of(context).maybePop();
|
||||||
Navigator.of(context).push(
|
context.pushNamed(RouteNames.profile);
|
||||||
MaterialPageRoute(builder: (_) => const ProfilePage()),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Platform.isIOS
|
Platform.isIOS
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import '../../../shared/theme/theme_extensions.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_animate/flutter_animate.dart';
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
import 'package:conduit/l10n/app_localizations.dart';
|
||||||
@@ -15,6 +16,7 @@ import '../../../shared/widgets/themed_dialogs.dart';
|
|||||||
import '../../../shared/widgets/sheet_handle.dart';
|
import '../../../shared/widgets/sheet_handle.dart';
|
||||||
import '../../../shared/widgets/conduit_components.dart';
|
import '../../../shared/widgets/conduit_components.dart';
|
||||||
import '../../../core/providers/app_providers.dart';
|
import '../../../core/providers/app_providers.dart';
|
||||||
|
import '../../../core/services/navigation_service.dart';
|
||||||
import '../../auth/providers/unified_auth_providers.dart';
|
import '../../auth/providers/unified_auth_providers.dart';
|
||||||
import '../../../core/services/settings_service.dart';
|
import '../../../core/services/settings_service.dart';
|
||||||
import '../../../core/models/model.dart';
|
import '../../../core/models/model.dart';
|
||||||
@@ -23,7 +25,6 @@ import '../../../core/models/user.dart' as models;
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import '../../chat/views/chat_page_helpers.dart';
|
import '../../chat/views/chat_page_helpers.dart';
|
||||||
import 'app_customization_page.dart';
|
|
||||||
import '../../../shared/widgets/modal_safe_area.dart';
|
import '../../../shared/widgets/modal_safe_area.dart';
|
||||||
import '../../../core/utils/user_display_name.dart';
|
import '../../../core/utils/user_display_name.dart';
|
||||||
import '../../../core/utils/user_avatar_utils.dart';
|
import '../../../core/utils/user_avatar_utils.dart';
|
||||||
@@ -338,9 +339,7 @@ class ProfilePage extends ConsumerWidget {
|
|||||||
title: AppLocalizations.of(context)!.appCustomization,
|
title: AppLocalizations.of(context)!.appCustomization,
|
||||||
subtitle: AppLocalizations.of(context)!.appCustomizationSubtitle,
|
subtitle: AppLocalizations.of(context)!.appCustomizationSubtitle,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).push(
|
context.pushNamed(RouteNames.appCustomization);
|
||||||
MaterialPageRoute(builder: (_) => const AppCustomizationPage()),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_buildAboutTile(context),
|
_buildAboutTile(context),
|
||||||
|
|||||||
255
lib/main.dart
255
lib/main.dart
@@ -1,25 +1,23 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'core/services/navigation_service.dart';
|
|
||||||
import 'core/widgets/error_boundary.dart';
|
import 'core/widgets/error_boundary.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'core/providers/app_providers.dart';
|
import 'core/providers/app_providers.dart';
|
||||||
|
import 'core/router/app_router.dart';
|
||||||
import 'shared/theme/app_theme.dart';
|
import 'shared/theme/app_theme.dart';
|
||||||
import 'shared/theme/theme_extensions.dart';
|
import 'shared/theme/theme_extensions.dart';
|
||||||
import 'shared/widgets/offline_indicator.dart';
|
import 'shared/widgets/offline_indicator.dart';
|
||||||
import 'features/auth/views/connect_signin_page.dart';
|
|
||||||
import 'features/auth/providers/unified_auth_providers.dart';
|
import 'features/auth/providers/unified_auth_providers.dart';
|
||||||
import 'core/auth/auth_state_manager.dart';
|
import 'core/auth/auth_state_manager.dart';
|
||||||
import 'core/utils/debug_logger.dart';
|
import 'core/utils/debug_logger.dart';
|
||||||
|
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
import 'package:conduit/l10n/app_localizations.dart';
|
||||||
import 'features/chat/views/chat_page.dart';
|
|
||||||
import 'features/navigation/views/splash_launcher_page.dart';
|
|
||||||
import 'core/services/share_receiver_service.dart';
|
import 'core/services/share_receiver_service.dart';
|
||||||
import 'core/providers/app_startup_providers.dart';
|
import 'core/providers/app_startup_providers.dart';
|
||||||
|
import 'core/models/server_config.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -64,46 +62,97 @@ class ConduitApp extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _ConduitAppState extends ConsumerState<ConduitApp> {
|
class _ConduitAppState extends ConsumerState<ConduitApp> {
|
||||||
bool _attemptedSilentAutoLogin = false;
|
bool _attemptedSilentAutoLogin = false;
|
||||||
|
ProviderSubscription<AuthNavigationState>? _authNavSubscription;
|
||||||
|
ProviderSubscription<AsyncValue<ServerConfig?>>? _activeServerSubscription;
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// Defer heavy provider initialization to after first frame to render UI sooner
|
// Defer heavy provider initialization to after first frame to render UI sooner
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _initializeAppState());
|
WidgetsBinding.instance.addPostFrameCallback((_) => _initializeAppState());
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildInitialLoadingSkeleton(BuildContext context) {
|
_authNavSubscription = ref.listenManual<AuthNavigationState>(
|
||||||
// Replace skeleton with branded splash during initialization
|
authNavigationStateProvider,
|
||||||
return const SplashLauncherPage();
|
(previous, next) {
|
||||||
|
if (next == AuthNavigationState.needsLogin) {
|
||||||
|
_maybeAttemptSilentLogin();
|
||||||
|
} else {
|
||||||
|
_attemptedSilentAutoLogin = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
_activeServerSubscription = ref.listenManual<AsyncValue<ServerConfig?>>(
|
||||||
|
activeServerProvider,
|
||||||
|
(previous, next) {
|
||||||
|
next.when(
|
||||||
|
data: (server) {
|
||||||
|
if (server != null) {
|
||||||
|
_maybeAttemptSilentLogin();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loading: () {},
|
||||||
|
error: (error, stackTrace) {},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Future.microtask(_maybeAttemptSilentLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _initializeAppState() {
|
void _initializeAppState() {
|
||||||
// Initialize unified auth state manager and API integration synchronously
|
|
||||||
// This ensures auth state is loaded before first widget build
|
|
||||||
DebugLogger.auth('Initializing unified auth system');
|
DebugLogger.auth('Initializing unified auth system');
|
||||||
|
|
||||||
// Initialize auth state manager (will handle token validation automatically)
|
|
||||||
ref.read(authStateManagerProvider);
|
ref.read(authStateManagerProvider);
|
||||||
|
|
||||||
// Ensure API service auth integration is active
|
|
||||||
ref.read(authApiIntegrationProvider);
|
ref.read(authApiIntegrationProvider);
|
||||||
|
|
||||||
// Initialize auto-selection listener for default model changes in settings
|
|
||||||
ref.read(defaultModelAutoSelectionProvider);
|
ref.read(defaultModelAutoSelectionProvider);
|
||||||
|
|
||||||
// Initialize OS share receiver so users can share text/files to Conduit
|
|
||||||
ref.read(shareReceiverInitializerProvider);
|
ref.read(shareReceiverInitializerProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_authNavSubscription?.close();
|
||||||
|
_activeServerSubscription?.close();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _maybeAttemptSilentLogin() {
|
||||||
|
if (_attemptedSilentAutoLogin) return;
|
||||||
|
|
||||||
|
final authState = ref.read(authNavigationStateProvider);
|
||||||
|
if (authState != AuthNavigationState.needsLogin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final activeServerAsync = ref.read(activeServerProvider);
|
||||||
|
final hasActiveServer = activeServerAsync.maybeWhen(
|
||||||
|
data: (server) => server != null,
|
||||||
|
orElse: () => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasActiveServer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_attemptedSilentAutoLogin = true;
|
||||||
|
|
||||||
|
Future.microtask(() async {
|
||||||
|
try {
|
||||||
|
final hasCreds = await ref.read(hasSavedCredentialsProvider2.future);
|
||||||
|
if (hasCreds) {
|
||||||
|
await ref.read(authActionsProvider).silentLogin();
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// Ignore silent login errors; fall back to manual login.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Use select to watch only the specific themeMode property to reduce rebuilds
|
|
||||||
final themeMode = ref.watch(themeModeProvider.select((mode) => mode));
|
final themeMode = ref.watch(themeModeProvider.select((mode) => mode));
|
||||||
|
final router = ref.watch(goRouterProvider);
|
||||||
|
ref.watch(appStartupFlowProvider);
|
||||||
|
|
||||||
// Reduced debug noise - only log when necessary
|
|
||||||
// debugPrint('DEBUG: Building app');
|
|
||||||
|
|
||||||
// Determine the current theme based on themeMode
|
|
||||||
// Default to Conduit brand theme globally
|
|
||||||
final currentTheme = themeMode == ThemeMode.dark
|
final currentTheme = themeMode == ThemeMode.dark
|
||||||
? AppTheme.conduitDarkTheme
|
? AppTheme.conduitDarkTheme
|
||||||
: themeMode == ThemeMode.light
|
: themeMode == ThemeMode.light
|
||||||
@@ -118,18 +167,18 @@ class _ConduitAppState extends ConsumerState<ConduitApp> {
|
|||||||
theme: currentTheme,
|
theme: currentTheme,
|
||||||
duration: AnimationDuration.medium,
|
duration: AnimationDuration.medium,
|
||||||
child: ErrorBoundary(
|
child: ErrorBoundary(
|
||||||
child: MaterialApp(
|
child: MaterialApp.router(
|
||||||
|
routerConfig: router,
|
||||||
onGenerateTitle: (context) => AppLocalizations.of(context)!.appTitle,
|
onGenerateTitle: (context) => AppLocalizations.of(context)!.appTitle,
|
||||||
theme: AppTheme.conduitLightTheme,
|
theme: AppTheme.conduitLightTheme,
|
||||||
darkTheme: AppTheme.conduitDarkTheme,
|
darkTheme: AppTheme.conduitDarkTheme,
|
||||||
themeMode: themeMode,
|
themeMode: themeMode,
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
navigatorKey: NavigationService.navigatorKey,
|
|
||||||
locale: locale,
|
locale: locale,
|
||||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
supportedLocales: AppLocalizations.supportedLocales,
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
localeListResolutionCallback: (deviceLocales, supported) {
|
localeListResolutionCallback: (deviceLocales, supported) {
|
||||||
if (locale != null) return locale; // User override wins
|
if (locale != null) return locale;
|
||||||
if (deviceLocales == null || deviceLocales.isEmpty) {
|
if (deviceLocales == null || deviceLocales.isEmpty) {
|
||||||
return supported.first;
|
return supported.first;
|
||||||
}
|
}
|
||||||
@@ -141,161 +190,19 @@ class _ConduitAppState extends ConsumerState<ConduitApp> {
|
|||||||
return supported.first;
|
return supported.first;
|
||||||
},
|
},
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
// Apply edge-to-edge inset handling and responsive design
|
final mediaQuery = MediaQuery.of(context);
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQuery.of(context).copyWith(
|
data: mediaQuery.copyWith(
|
||||||
// Ensure proper text scaling for edge-to-edge
|
textScaler: mediaQuery.textScaler.clamp(
|
||||||
textScaler: MediaQuery.of(
|
minScaleFactor: 0.8,
|
||||||
context,
|
maxScaleFactor: 1.3,
|
||||||
).textScaler.clamp(minScaleFactor: 0.8, maxScaleFactor: 1.3),
|
),
|
||||||
),
|
),
|
||||||
child: OfflineIndicator(child: child ?? const SizedBox.shrink()),
|
child: OfflineIndicator(child: child ?? const SizedBox.shrink()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
home: _getInitialPageWithReactiveState(),
|
|
||||||
onGenerateRoute: NavigationService.generateRoute,
|
|
||||||
navigatorObservers: [_NavigationObserver()],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getInitialPageWithReactiveState() {
|
|
||||||
return Consumer(
|
|
||||||
builder: (context, ref, child) {
|
|
||||||
// Watch for server connection state changes
|
|
||||||
final activeServerAsync = ref.watch(activeServerProvider);
|
|
||||||
final reviewerMode = ref.watch(reviewerModeProvider);
|
|
||||||
|
|
||||||
if (reviewerMode) {
|
|
||||||
// In reviewer mode, skip server/auth flows and go to chat
|
|
||||||
NavigationService.setCurrentRoute(Routes.chat);
|
|
||||||
return const ChatPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return activeServerAsync.when(
|
|
||||||
data: (activeServer) {
|
|
||||||
if (activeServer == null) {
|
|
||||||
return const ConnectAndSignInPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server is connected, now check authentication reactively
|
|
||||||
final authNavState = ref.watch(authNavigationStateProvider);
|
|
||||||
|
|
||||||
if (authNavState == AuthNavigationState.needsLogin) {
|
|
||||||
// Try one-shot silent login if credentials are saved
|
|
||||||
if (!_attemptedSilentAutoLogin) {
|
|
||||||
_attemptedSilentAutoLogin = true;
|
|
||||||
Future.microtask(() async {
|
|
||||||
try {
|
|
||||||
final hasCreds = await ref.read(
|
|
||||||
hasSavedCredentialsProvider2.future,
|
|
||||||
);
|
|
||||||
if (hasCreds) {
|
|
||||||
await ref.read(authActionsProvider).silentLogin();
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
// Ignore errors, fallback to showing unified page
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return const ConnectAndSignInPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authNavState == AuthNavigationState.loading) {
|
|
||||||
return _buildInitialLoadingSkeleton(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authNavState == AuthNavigationState.error) {
|
|
||||||
return _buildErrorState(
|
|
||||||
ref.watch(authErrorProvider3) ??
|
|
||||||
AppLocalizations.of(context)!.errorMessage,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// User is authenticated, navigate directly to chat page
|
|
||||||
// Kick off and keep app startup/background task flow alive
|
|
||||||
ref.watch(appStartupFlowProvider);
|
|
||||||
|
|
||||||
// Set the current route for navigation tracking
|
|
||||||
NavigationService.setCurrentRoute(Routes.chat);
|
|
||||||
|
|
||||||
return const ChatPage();
|
|
||||||
},
|
|
||||||
loading: () => _buildInitialLoadingSkeleton(context),
|
|
||||||
error: (error, stackTrace) {
|
|
||||||
DebugLogger.error('Server provider error', error);
|
|
||||||
return _buildErrorState(
|
|
||||||
AppLocalizations.of(context)!.unableToConnectServer,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Background initialization moved to app-based task flow provider
|
|
||||||
|
|
||||||
Widget _buildErrorState(String error) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: context.conduitTheme.surfaceBackground,
|
|
||||||
body: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(Spacing.lg),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.error_outline,
|
|
||||||
size: IconSize.xxl + Spacing.md,
|
|
||||||
color: context.conduitTheme.error,
|
|
||||||
),
|
|
||||||
const SizedBox(height: Spacing.md),
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context)!.initializationFailed,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: AppTypography.headlineLarge,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: context.conduitTheme.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: Spacing.sm),
|
|
||||||
Text(
|
|
||||||
error,
|
|
||||||
style: TextStyle(color: context.conduitTheme.textSecondary),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
const SizedBox(height: Spacing.lg),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
// Restart the app
|
|
||||||
WidgetsBinding.instance.reassembleApplication();
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: context.conduitTheme.buttonPrimary,
|
|
||||||
foregroundColor: context.conduitTheme.buttonPrimaryText,
|
|
||||||
),
|
|
||||||
child: Text(AppLocalizations.of(context)!.retry),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _NavigationObserver extends NavigatorObserver {
|
|
||||||
@override
|
|
||||||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
||||||
super.didPush(route, previousRoute);
|
|
||||||
// Log navigation for debugging and analytics
|
|
||||||
DebugLogger.navigation('Pushed: ${route.settings.name}');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
||||||
super.didPop(route, previousRoute);
|
|
||||||
DebugLogger.navigation('Popped: ${route.settings.name}');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -517,6 +517,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3"
|
version: "2.1.3"
|
||||||
|
go_router:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: go_router
|
||||||
|
sha256: f02fd7d2a4dc512fec615529824fdd217fecb3a3d3de68360293a551f21634b3
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "14.8.1"
|
||||||
graphs:
|
graphs:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ dependencies:
|
|||||||
# State Management
|
# State Management
|
||||||
flutter_riverpod: ^3.0.0
|
flutter_riverpod: ^3.0.0
|
||||||
|
|
||||||
|
# Navigation
|
||||||
|
go_router: ^14.2.0
|
||||||
|
|
||||||
# Network & API
|
# Network & API
|
||||||
dio: ^5.9.0
|
dio: ^5.9.0
|
||||||
http_parser: ^4.0.2
|
http_parser: ^4.0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user