2025-08-10 01:20:45 +05:30
|
|
|
import 'package:flutter/material.dart';
|
2025-08-21 23:56:47 +05:30
|
|
|
import 'package:flutter/services.dart';
|
2025-08-10 01:20:45 +05:30
|
|
|
import '../../../shared/theme/theme_extensions.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2025-09-22 14:36:43 +05:30
|
|
|
import 'package:go_router/go_router.dart';
|
2025-08-10 01:20:45 +05:30
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2025-08-23 20:09:43 +05:30
|
|
|
import 'package:conduit/l10n/app_localizations.dart';
|
2025-08-10 01:20:45 +05:30
|
|
|
import '../../../core/widgets/error_boundary.dart';
|
|
|
|
|
import '../../../shared/widgets/improved_loading_states.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../shared/utils/ui_utils.dart';
|
2025-09-07 23:48:47 +05:30
|
|
|
import '../../../shared/widgets/themed_dialogs.dart';
|
2025-08-22 01:24:04 +05:30
|
|
|
import '../../../shared/widgets/sheet_handle.dart';
|
2025-08-10 01:20:45 +05:30
|
|
|
import '../../../shared/widgets/conduit_components.dart';
|
|
|
|
|
import '../../../core/providers/app_providers.dart';
|
2025-09-22 14:36:43 +05:30
|
|
|
import '../../../core/services/navigation_service.dart';
|
2025-12-22 16:19:50 +05:30
|
|
|
import '../../chat/providers/chat_providers.dart' show restoreDefaultModel;
|
2025-08-10 01:20:45 +05:30
|
|
|
import '../../auth/providers/unified_auth_providers.dart';
|
2025-08-17 17:01:06 +05:30
|
|
|
import '../../../core/services/settings_service.dart';
|
|
|
|
|
import '../../../core/models/model.dart';
|
2025-09-20 22:03:55 +05:30
|
|
|
import '../../../core/services/api_service.dart';
|
|
|
|
|
import '../../../core/models/user.dart' as models;
|
2025-08-17 17:01:06 +05:30
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import '../../chat/views/chat_page_helpers.dart';
|
2025-09-19 21:12:15 +05:30
|
|
|
import '../../../shared/widgets/modal_safe_area.dart';
|
2025-09-20 22:03:55 +05:30
|
|
|
import '../../../core/utils/user_display_name.dart';
|
|
|
|
|
import '../../../core/utils/user_avatar_utils.dart';
|
|
|
|
|
import '../../../core/utils/model_icon_utils.dart';
|
|
|
|
|
import '../../../shared/widgets/user_avatar.dart';
|
|
|
|
|
import '../../../shared/widgets/model_avatar.dart';
|
2025-08-10 01:20:45 +05:30
|
|
|
|
|
|
|
|
/// Profile page (You tab) showing user info and main actions
|
|
|
|
|
/// Enhanced with production-grade design tokens for better cohesion
|
|
|
|
|
class ProfilePage extends ConsumerWidget {
|
2025-10-02 15:14:34 +05:30
|
|
|
static const _githubSponsorsUrl = 'https://github.com/sponsors/cogwheel0';
|
|
|
|
|
static const _buyMeACoffeeUrl = 'https://www.buymeacoffee.com/cogwheel0';
|
|
|
|
|
|
2025-08-10 01:20:45 +05:30
|
|
|
const ProfilePage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2025-11-27 21:41:32 +05:30
|
|
|
final authUser = ref.watch(currentUserProvider2);
|
|
|
|
|
final asyncUser = ref.watch(currentUserProvider);
|
|
|
|
|
final user = asyncUser.maybeWhen(
|
|
|
|
|
data: (value) => value ?? authUser,
|
|
|
|
|
orElse: () => authUser,
|
|
|
|
|
);
|
2025-11-26 19:16:14 +05:30
|
|
|
final isAuthLoading = ref.watch(isAuthLoadingProvider2);
|
2025-09-20 22:03:55 +05:30
|
|
|
final api = ref.watch(apiServiceProvider);
|
2025-08-10 01:20:45 +05:30
|
|
|
|
2025-11-26 19:16:14 +05:30
|
|
|
Widget body;
|
|
|
|
|
if (isAuthLoading && user == null) {
|
|
|
|
|
body = _buildCenteredState(
|
|
|
|
|
context,
|
|
|
|
|
ImprovedLoadingState(
|
|
|
|
|
message: AppLocalizations.of(context)!.loadingProfile,
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-11-26 19:16:14 +05:30
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
body = _buildProfileBody(context, ref, user, api);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorBoundary(child: _buildScaffold(context, body: body));
|
2025-09-20 23:02:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Scaffold _buildScaffold(BuildContext context, {required Widget body}) {
|
2025-12-15 20:03:29 +05:30
|
|
|
final canPop = ModalRoute.of(context)?.canPop ?? false;
|
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
|
|
2025-09-20 23:02:59 +05:30
|
|
|
return Scaffold(
|
2025-12-15 20:17:56 +05:30
|
|
|
backgroundColor: context.conduitTheme.surfaceBackground,
|
2025-12-15 20:03:29 +05:30
|
|
|
extendBodyBehindAppBar: true,
|
2025-12-15 20:17:56 +05:30
|
|
|
appBar: FloatingAppBar(
|
|
|
|
|
leading: canPop ? const FloatingAppBarBackButton() : null,
|
|
|
|
|
title: FloatingAppBarTitle(text: l10n.you),
|
2025-12-15 20:03:29 +05:30
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
body: body,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildCenteredState(BuildContext context, Widget child) {
|
2025-12-15 20:03:29 +05:30
|
|
|
final topPadding = MediaQuery.of(context).padding.top + kToolbarHeight + 24;
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
|
Spacing.pagePadding,
|
|
|
|
|
topPadding,
|
|
|
|
|
Spacing.pagePadding,
|
|
|
|
|
Spacing.pagePadding + MediaQuery.of(context).padding.bottom,
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-12-15 20:03:29 +05:30
|
|
|
child: Center(child: child),
|
2025-09-20 23:02:59 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildProfileBody(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
WidgetRef ref,
|
|
|
|
|
dynamic userData,
|
|
|
|
|
ApiService? api,
|
|
|
|
|
) {
|
2025-12-15 20:03:29 +05:30
|
|
|
// Calculate top padding to account for app bar + safe area
|
|
|
|
|
final topPadding = MediaQuery.of(context).padding.top + kToolbarHeight + 24;
|
|
|
|
|
|
|
|
|
|
return ListView(
|
|
|
|
|
physics: const BouncingScrollPhysics(
|
|
|
|
|
parent: AlwaysScrollableScrollPhysics(),
|
|
|
|
|
),
|
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
|
Spacing.pagePadding,
|
|
|
|
|
topPadding,
|
|
|
|
|
Spacing.pagePadding,
|
|
|
|
|
Spacing.pagePadding + MediaQuery.of(context).padding.bottom,
|
2025-10-02 15:14:34 +05:30
|
|
|
),
|
2025-12-15 20:03:29 +05:30
|
|
|
children: [
|
|
|
|
|
_buildProfileHeader(context, userData, api),
|
|
|
|
|
const SizedBox(height: Spacing.xl),
|
|
|
|
|
_buildAccountSection(context, ref),
|
|
|
|
|
const SizedBox(height: Spacing.xl),
|
|
|
|
|
_buildSupportSection(context),
|
|
|
|
|
],
|
2025-10-02 15:14:34 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSupportSection(BuildContext context) {
|
|
|
|
|
final theme = context.conduitTheme;
|
|
|
|
|
final textTheme =
|
2025-10-18 13:58:15 +05:30
|
|
|
theme.bodySmall?.copyWith(
|
|
|
|
|
color: theme.sidebarForeground.withValues(alpha: 0.75),
|
|
|
|
|
) ??
|
|
|
|
|
TextStyle(color: theme.sidebarForeground.withValues(alpha: 0.75));
|
2025-10-02 15:14:34 +05:30
|
|
|
|
|
|
|
|
final supportTiles = [
|
|
|
|
|
_buildSupportOption(
|
|
|
|
|
context,
|
|
|
|
|
icon: UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.gift,
|
|
|
|
|
android: Icons.coffee,
|
|
|
|
|
),
|
|
|
|
|
title: AppLocalizations.of(context)!.buyMeACoffeeTitle,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.buyMeACoffeeSubtitle,
|
|
|
|
|
url: _buyMeACoffeeUrl,
|
|
|
|
|
color: theme.warning,
|
|
|
|
|
),
|
2025-10-17 15:09:37 +05:30
|
|
|
_buildSupportOption(
|
|
|
|
|
context,
|
|
|
|
|
icon: UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.heart,
|
|
|
|
|
android: Icons.favorite_border,
|
|
|
|
|
),
|
|
|
|
|
title: AppLocalizations.of(context)!.githubSponsorsTitle,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.githubSponsorsSubtitle,
|
|
|
|
|
url: _githubSponsorsUrl,
|
|
|
|
|
color: theme.success,
|
|
|
|
|
),
|
2025-10-02 15:14:34 +05:30
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
AppLocalizations.of(context)!.supportConduit,
|
2025-10-18 13:58:15 +05:30
|
|
|
style: theme.headingSmall?.copyWith(color: theme.sidebarForeground),
|
2025-10-02 15:14:34 +05:30
|
|
|
),
|
|
|
|
|
const SizedBox(height: Spacing.xs),
|
|
|
|
|
Text(
|
|
|
|
|
AppLocalizations.of(context)!.supportConduitSubtitle,
|
|
|
|
|
style: textTheme,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: Spacing.sm),
|
|
|
|
|
for (var i = 0; i < supportTiles.length; i++) ...[
|
|
|
|
|
supportTiles[i],
|
|
|
|
|
if (i != supportTiles.length - 1) const SizedBox(height: Spacing.md),
|
2025-09-20 23:02:59 +05:30
|
|
|
],
|
2025-10-02 15:14:34 +05:30
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSupportOption(
|
|
|
|
|
BuildContext context, {
|
|
|
|
|
required IconData icon,
|
|
|
|
|
required String title,
|
|
|
|
|
required String subtitle,
|
|
|
|
|
required String url,
|
|
|
|
|
required Color color,
|
|
|
|
|
}) {
|
|
|
|
|
final theme = context.conduitTheme;
|
|
|
|
|
return _ProfileSettingTile(
|
|
|
|
|
onTap: () => _openExternalLink(context, url),
|
|
|
|
|
leading: _buildIconBadge(context, icon, color: color),
|
|
|
|
|
title: title,
|
|
|
|
|
subtitle: subtitle,
|
|
|
|
|
trailing: Icon(
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.arrow_up_right,
|
|
|
|
|
android: Icons.open_in_new,
|
|
|
|
|
),
|
|
|
|
|
color: theme.iconSecondary,
|
|
|
|
|
size: IconSize.small,
|
2025-08-10 01:20:45 +05:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 15:14:34 +05:30
|
|
|
Future<void> _openExternalLink(BuildContext context, String url) async {
|
|
|
|
|
try {
|
|
|
|
|
final launched = await launchUrlString(
|
|
|
|
|
url,
|
|
|
|
|
mode: LaunchMode.externalApplication,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!launched && context.mounted) {
|
|
|
|
|
UiUtils.showMessage(
|
|
|
|
|
context,
|
|
|
|
|
AppLocalizations.of(context)!.errorMessage,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} on PlatformException catch (_) {
|
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
UiUtils.showMessage(context, AppLocalizations.of(context)!.errorMessage);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
UiUtils.showMessage(context, AppLocalizations.of(context)!.errorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 22:03:55 +05:30
|
|
|
Widget _buildProfileHeader(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
dynamic user,
|
|
|
|
|
ApiService? api,
|
|
|
|
|
) {
|
|
|
|
|
final displayName = deriveUserDisplayName(user);
|
|
|
|
|
final characters = displayName.characters;
|
|
|
|
|
final initial = characters.isNotEmpty
|
|
|
|
|
? characters.first.toUpperCase()
|
|
|
|
|
: 'U';
|
|
|
|
|
final avatarUrl = resolveUserAvatarUrlForUser(api, user);
|
|
|
|
|
|
|
|
|
|
String? extractEmail(dynamic source) {
|
|
|
|
|
if (source is models.User) {
|
|
|
|
|
return source.email;
|
|
|
|
|
}
|
|
|
|
|
if (source is Map) {
|
|
|
|
|
final value = source['email'];
|
|
|
|
|
if (value is String && value.trim().isNotEmpty) {
|
|
|
|
|
return value.trim();
|
|
|
|
|
}
|
|
|
|
|
final nested = source['user'];
|
|
|
|
|
if (nested is Map) {
|
|
|
|
|
final nestedValue = nested['email'];
|
|
|
|
|
if (nestedValue is String && nestedValue.trim().isNotEmpty) {
|
|
|
|
|
return nestedValue.trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final email = extractEmail(user) ?? 'No email';
|
2025-09-20 23:02:59 +05:30
|
|
|
final theme = context.conduitTheme;
|
2025-09-20 22:03:55 +05:30
|
|
|
|
2025-09-20 23:02:59 +05:30
|
|
|
return Container(
|
2025-10-05 00:29:27 +05:30
|
|
|
padding: const EdgeInsets.all(Spacing.md),
|
2025-09-20 23:02:59 +05:30
|
|
|
decoration: BoxDecoration(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: theme.sidebarAccent.withValues(alpha: 0.6),
|
2025-10-05 00:29:27 +05:30
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.large),
|
2025-09-20 23:02:59 +05:30
|
|
|
border: Border.all(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: theme.sidebarBorder.withValues(alpha: 0.6),
|
2025-09-20 23:02:59 +05:30
|
|
|
width: BorderWidth.thin,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2025-09-20 22:03:55 +05:30
|
|
|
children: [
|
2025-09-20 23:02:59 +05:30
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
2025-10-05 00:59:32 +05:30
|
|
|
UserAvatar(size: 56, imageUrl: avatarUrl, fallbackText: initial),
|
2025-10-02 15:17:37 +05:30
|
|
|
const SizedBox(width: Spacing.md),
|
2025-09-20 23:02:59 +05:30
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
displayName,
|
2025-10-05 00:29:27 +05:30
|
|
|
style: theme.headingMedium?.copyWith(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: theme.sidebarForeground,
|
2025-10-05 00:29:27 +05:30
|
|
|
fontWeight: FontWeight.w600,
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
),
|
|
|
|
|
const SizedBox(height: Spacing.xs),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.envelope,
|
|
|
|
|
android: Icons.mail_outline,
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
size: IconSize.small,
|
2025-10-18 13:58:15 +05:30
|
|
|
color: theme.sidebarForeground.withValues(
|
|
|
|
|
alpha: 0.75,
|
|
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
),
|
|
|
|
|
const SizedBox(width: Spacing.xs),
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Text(
|
|
|
|
|
email,
|
|
|
|
|
style: theme.bodySmall?.copyWith(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: theme.sidebarForeground.withValues(
|
|
|
|
|
alpha: 0.75,
|
|
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 1,
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
),
|
|
|
|
|
],
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-09-20 22:03:55 +05:30
|
|
|
),
|
|
|
|
|
],
|
2025-08-10 01:20:45 +05:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildAccountSection(BuildContext context, WidgetRef ref) {
|
2025-09-20 23:02:59 +05:30
|
|
|
final items = [
|
|
|
|
|
_buildDefaultModelTile(context, ref),
|
|
|
|
|
_buildAccountOption(
|
|
|
|
|
context,
|
|
|
|
|
icon: UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.slider_horizontal_3,
|
|
|
|
|
android: Icons.tune,
|
|
|
|
|
),
|
|
|
|
|
title: AppLocalizations.of(context)!.appCustomization,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.appCustomizationSubtitle,
|
|
|
|
|
onTap: () {
|
2025-09-22 14:36:43 +05:30
|
|
|
context.pushNamed(RouteNames.appCustomization);
|
2025-09-20 23:02:59 +05:30
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
_buildAboutTile(context),
|
|
|
|
|
_buildAccountOption(
|
|
|
|
|
context,
|
|
|
|
|
icon: UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.square_arrow_left,
|
|
|
|
|
android: Icons.logout,
|
|
|
|
|
),
|
|
|
|
|
title: AppLocalizations.of(context)!.signOut,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.endYourSession,
|
|
|
|
|
onTap: () => _signOut(context, ref),
|
|
|
|
|
showChevron: false,
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
2025-08-10 01:20:45 +05:30
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
2025-09-20 23:02:59 +05:30
|
|
|
for (var i = 0; i < items.length; i++) ...[
|
|
|
|
|
items[i],
|
|
|
|
|
if (i != items.length - 1) const SizedBox(height: Spacing.md),
|
|
|
|
|
],
|
2025-08-10 01:20:45 +05:30
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 23:02:59 +05:30
|
|
|
Widget _buildAccountOption(
|
|
|
|
|
BuildContext context, {
|
2025-08-10 01:20:45 +05:30
|
|
|
required IconData icon,
|
|
|
|
|
required String title,
|
|
|
|
|
required String subtitle,
|
|
|
|
|
required VoidCallback onTap,
|
2025-09-20 23:02:59 +05:30
|
|
|
bool showChevron = true,
|
2025-08-10 01:20:45 +05:30
|
|
|
}) {
|
2025-09-20 23:02:59 +05:30
|
|
|
final theme = context.conduitTheme;
|
2025-10-18 13:58:15 +05:30
|
|
|
final color = theme.buttonPrimary;
|
2025-09-20 23:02:59 +05:30
|
|
|
return _ProfileSettingTile(
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
leading: _buildIconBadge(context, icon, color: color),
|
|
|
|
|
title: title,
|
|
|
|
|
subtitle: subtitle,
|
|
|
|
|
trailing: showChevron
|
|
|
|
|
? Icon(
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.chevron_right,
|
|
|
|
|
android: Icons.chevron_right,
|
|
|
|
|
),
|
|
|
|
|
color: theme.iconSecondary,
|
|
|
|
|
size: IconSize.small,
|
|
|
|
|
)
|
|
|
|
|
: null,
|
2025-08-10 01:20:45 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
Widget _buildDefaultModelTile(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final settings = ref.watch(appSettingsProvider);
|
|
|
|
|
final modelsAsync = ref.watch(modelsProvider);
|
2025-09-20 22:03:55 +05:30
|
|
|
final api = ref.watch(apiServiceProvider);
|
2025-08-24 20:27:11 +05:30
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
return modelsAsync.when(
|
|
|
|
|
data: (models) {
|
|
|
|
|
final currentModel = models.firstWhere(
|
|
|
|
|
(m) => m.id == settings.defaultModel,
|
2025-08-24 20:27:11 +05:30
|
|
|
orElse: () => models.isNotEmpty
|
|
|
|
|
? models.first
|
2025-09-19 21:12:15 +05:30
|
|
|
: Model(
|
|
|
|
|
id: 'none',
|
|
|
|
|
name: AppLocalizations.of(context)!.noModelsAvailable,
|
|
|
|
|
),
|
2025-08-17 17:01:06 +05:30
|
|
|
);
|
2025-08-24 20:27:11 +05:30
|
|
|
|
2025-09-20 22:03:55 +05:30
|
|
|
final selectedModelExplicit = settings.defaultModel != null;
|
|
|
|
|
final modelIconUrl = selectedModelExplicit
|
|
|
|
|
? resolveModelIconUrlForModel(api, currentModel)
|
|
|
|
|
: null;
|
|
|
|
|
final modelLabel = selectedModelExplicit
|
|
|
|
|
? currentModel.name
|
|
|
|
|
: AppLocalizations.of(context)!.autoSelect;
|
|
|
|
|
|
2025-09-20 23:02:59 +05:30
|
|
|
final theme = context.conduitTheme;
|
|
|
|
|
|
2025-09-20 22:03:55 +05:30
|
|
|
Widget leading;
|
|
|
|
|
if (selectedModelExplicit) {
|
|
|
|
|
leading = Container(
|
2025-10-05 00:29:27 +05:30
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
2025-08-17 17:01:06 +05:30
|
|
|
decoration: BoxDecoration(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: theme.sidebarAccent.withValues(alpha: 0.8),
|
2025-10-05 00:29:27 +05:30
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.small),
|
2025-09-20 23:02:59 +05:30
|
|
|
border: Border.all(
|
|
|
|
|
color: theme.cardBorder,
|
|
|
|
|
width: BorderWidth.thin,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
alignment: Alignment.center,
|
|
|
|
|
child: ModelAvatar(
|
2025-10-05 00:29:27 +05:30
|
|
|
size: 28,
|
2025-09-20 23:02:59 +05:30
|
|
|
imageUrl: modelIconUrl,
|
|
|
|
|
label: currentModel.name,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-20 22:03:55 +05:30
|
|
|
);
|
2025-09-20 23:02:59 +05:30
|
|
|
} else {
|
|
|
|
|
leading = _buildIconBadge(
|
|
|
|
|
context,
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.wand_stars,
|
|
|
|
|
android: Icons.auto_awesome,
|
|
|
|
|
),
|
|
|
|
|
color: theme.buttonPrimary,
|
|
|
|
|
);
|
2025-09-20 22:03:55 +05:30
|
|
|
}
|
|
|
|
|
|
2025-09-20 23:02:59 +05:30
|
|
|
return _ProfileSettingTile(
|
2025-09-20 22:03:55 +05:30
|
|
|
leading: leading,
|
2025-09-20 23:02:59 +05:30
|
|
|
title: AppLocalizations.of(context)!.defaultModel,
|
|
|
|
|
subtitle: modelLabel,
|
2025-08-17 17:01:06 +05:30
|
|
|
onTap: () => _showModelSelector(context, ref, models),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-09-20 23:02:59 +05:30
|
|
|
loading: () => _ProfileSettingTile(
|
|
|
|
|
leading: _buildIconBadge(
|
|
|
|
|
context,
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.cube_box,
|
|
|
|
|
android: Icons.psychology,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
color: context.conduitTheme.buttonPrimary,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
title: AppLocalizations.of(context)!.defaultModel,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.loadingModels,
|
|
|
|
|
showChevron: false,
|
|
|
|
|
trailing: SizedBox(
|
|
|
|
|
width: 20,
|
|
|
|
|
height: 20,
|
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
|
strokeWidth: 2,
|
|
|
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
|
|
|
|
context.conduitTheme.buttonPrimary,
|
|
|
|
|
),
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
error: (error, stack) => _ProfileSettingTile(
|
|
|
|
|
leading: _buildIconBadge(
|
|
|
|
|
context,
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.exclamationmark_triangle,
|
|
|
|
|
android: Icons.error_outline,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-10-18 13:58:15 +05:30
|
|
|
color: Colors.red,
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
|
|
|
|
title: AppLocalizations.of(context)!.defaultModel,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.failedToLoadModels,
|
|
|
|
|
showChevron: false,
|
|
|
|
|
onTap: () => ref.invalidate(modelsProvider),
|
|
|
|
|
trailing: IconButton(
|
|
|
|
|
onPressed: () => ref.invalidate(modelsProvider),
|
|
|
|
|
tooltip: AppLocalizations.of(context)!.retry,
|
|
|
|
|
icon: Icon(
|
2025-08-17 17:01:06 +05:30
|
|
|
UiUtils.platformIcon(
|
2025-09-20 23:02:59 +05:30
|
|
|
ios: CupertinoIcons.refresh,
|
|
|
|
|
android: Icons.refresh,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-10-18 13:58:15 +05:30
|
|
|
color: Colors.red,
|
2025-09-20 23:02:59 +05:30
|
|
|
size: IconSize.small,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildIconBadge(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
IconData icon, {
|
|
|
|
|
required Color color,
|
|
|
|
|
}) {
|
|
|
|
|
return Container(
|
2025-10-05 00:29:27 +05:30
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
2025-09-20 23:02:59 +05:30
|
|
|
decoration: BoxDecoration(
|
2025-10-05 00:29:27 +05:30
|
|
|
color: color.withValues(alpha: 0.1),
|
|
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.small),
|
2025-09-20 23:02:59 +05:30
|
|
|
border: Border.all(
|
|
|
|
|
color: color.withValues(alpha: 0.2),
|
|
|
|
|
width: BorderWidth.thin,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
alignment: Alignment.center,
|
2025-10-05 00:29:27 +05:30
|
|
|
child: Icon(icon, color: color, size: IconSize.medium),
|
2025-08-17 17:01:06 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-07 11:29:29 +05:30
|
|
|
// Theme and language controls moved to AppCustomizationPage.
|
2025-08-10 01:20:45 +05:30
|
|
|
|
|
|
|
|
Widget _buildAboutTile(BuildContext context) {
|
|
|
|
|
return _buildAccountOption(
|
2025-09-20 23:02:59 +05:30
|
|
|
context,
|
2025-08-10 01:20:45 +05:30
|
|
|
icon: UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.info,
|
|
|
|
|
android: Icons.info_outline,
|
|
|
|
|
),
|
2025-08-23 23:56:53 +05:30
|
|
|
title: AppLocalizations.of(context)!.aboutApp,
|
|
|
|
|
subtitle: AppLocalizations.of(context)!.aboutAppSubtitle,
|
2025-08-10 01:20:45 +05:30
|
|
|
onTap: () => _showAboutDialog(context),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _showAboutDialog(BuildContext context) async {
|
|
|
|
|
try {
|
|
|
|
|
final info = await PackageInfo.fromPlatform();
|
|
|
|
|
// Update dialog with dynamic version each time
|
|
|
|
|
// GitHub repo URL source of truth
|
|
|
|
|
const githubUrl = 'https://github.com/cogwheel0/conduit';
|
|
|
|
|
|
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
await showDialog<void>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (ctx) {
|
|
|
|
|
return AlertDialog(
|
2025-10-18 13:58:15 +05:30
|
|
|
backgroundColor: ctx.sidebarTheme.background,
|
2025-08-10 01:20:45 +05:30
|
|
|
title: Text(
|
2025-08-28 23:46:32 +05:30
|
|
|
AppLocalizations.of(ctx)!.aboutConduit,
|
2025-08-10 01:20:45 +05:30
|
|
|
style: ctx.conduitTheme.headingSmall?.copyWith(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: ctx.sidebarTheme.foreground,
|
2025-08-10 01:20:45 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
content: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
2025-09-19 21:12:15 +05:30
|
|
|
AppLocalizations.of(
|
|
|
|
|
ctx,
|
|
|
|
|
)!.versionLabel(info.version, info.buildNumber),
|
2025-08-10 01:20:45 +05:30
|
|
|
style: ctx.conduitTheme.bodyMedium?.copyWith(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: ctx.sidebarTheme.foreground.withValues(alpha: 0.75),
|
2025-08-10 01:20:45 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: Spacing.md),
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => launchUrlString(
|
|
|
|
|
githubUrl,
|
|
|
|
|
mode: LaunchMode.externalApplication,
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.link,
|
|
|
|
|
android: Icons.link,
|
|
|
|
|
),
|
|
|
|
|
size: IconSize.small,
|
|
|
|
|
color: ctx.conduitTheme.buttonPrimary,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: Spacing.xs),
|
|
|
|
|
Text(
|
2025-08-28 23:46:32 +05:30
|
|
|
AppLocalizations.of(ctx)!.githubRepository,
|
2025-08-10 01:20:45 +05:30
|
|
|
style: ctx.conduitTheme.bodyMedium?.copyWith(
|
|
|
|
|
color: ctx.conduitTheme.buttonPrimary,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.of(ctx).pop(),
|
2025-08-23 20:09:43 +05:30
|
|
|
child: Text(AppLocalizations.of(ctx)!.closeButtonSemantic),
|
2025-08-10 01:20:45 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (!context.mounted) return;
|
2025-09-19 21:12:15 +05:30
|
|
|
UiUtils.showMessage(
|
|
|
|
|
context,
|
|
|
|
|
AppLocalizations.of(context)!.unableToLoadAppInfo,
|
|
|
|
|
);
|
2025-08-10 01:20:45 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 20:27:11 +05:30
|
|
|
Future<void> _showModelSelector(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
WidgetRef ref,
|
|
|
|
|
List<Model> models,
|
|
|
|
|
) async {
|
2025-08-17 17:01:06 +05:30
|
|
|
final result = await showModalBottomSheet<String?>(
|
|
|
|
|
context: context,
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
|
builder: (ctx) => _DefaultModelBottomSheet(
|
|
|
|
|
models: models,
|
|
|
|
|
currentDefaultModelId: ref.read(appSettingsProvider).defaultModel,
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-08-24 20:27:11 +05:30
|
|
|
|
2025-08-17 17:43:19 +05:30
|
|
|
// result is non-null only when Save button is pressed
|
|
|
|
|
// null means the sheet was dismissed without saving
|
|
|
|
|
if (result != null) {
|
|
|
|
|
// Handle special case: 'auto-select' should be stored as null
|
|
|
|
|
final modelIdToSave = result == 'auto-select' ? null : result;
|
2025-08-24 20:27:11 +05:30
|
|
|
await ref
|
|
|
|
|
.read(appSettingsProvider.notifier)
|
|
|
|
|
.setDefaultModel(modelIdToSave);
|
2025-12-22 16:19:50 +05:30
|
|
|
|
|
|
|
|
// Immediately apply the new default model selection
|
|
|
|
|
await restoreDefaultModel(ref);
|
2025-08-17 17:01:06 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 01:20:45 +05:30
|
|
|
void _signOut(BuildContext context, WidgetRef ref) async {
|
2025-09-07 23:48:47 +05:30
|
|
|
final confirm = await ThemedDialogs.confirm(
|
2025-08-10 01:20:45 +05:30
|
|
|
context,
|
2025-08-23 20:09:43 +05:30
|
|
|
title: AppLocalizations.of(context)!.signOut,
|
|
|
|
|
message: AppLocalizations.of(context)!.endYourSession,
|
|
|
|
|
confirmText: AppLocalizations.of(context)!.signOut,
|
2025-08-10 01:20:45 +05:30
|
|
|
isDestructive: true,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (confirm) {
|
2025-08-29 12:58:56 +05:30
|
|
|
await ref.read(authActionsProvider).logout();
|
2025-08-10 01:20:45 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-17 17:01:06 +05:30
|
|
|
|
2025-09-20 23:02:59 +05:30
|
|
|
class _ProfileSettingTile extends StatelessWidget {
|
|
|
|
|
const _ProfileSettingTile({
|
|
|
|
|
required this.leading,
|
|
|
|
|
required this.title,
|
|
|
|
|
required this.subtitle,
|
|
|
|
|
this.onTap,
|
|
|
|
|
this.trailing,
|
|
|
|
|
this.showChevron = true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final Widget leading;
|
|
|
|
|
final String title;
|
|
|
|
|
final String subtitle;
|
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
|
final Widget? trailing;
|
|
|
|
|
final bool showChevron;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = context.conduitTheme;
|
2025-10-18 13:58:15 +05:30
|
|
|
final textColor = theme.sidebarForeground;
|
|
|
|
|
final subtitleColor = theme.sidebarForeground.withValues(alpha: 0.75);
|
2025-09-20 23:02:59 +05:30
|
|
|
|
|
|
|
|
return ConduitCard(
|
2025-10-05 00:29:27 +05:30
|
|
|
padding: const EdgeInsets.all(Spacing.md),
|
2025-09-20 23:02:59 +05:30
|
|
|
onTap: onTap,
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
leading,
|
|
|
|
|
const SizedBox(width: Spacing.md),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
title,
|
2025-10-05 00:29:27 +05:30
|
|
|
style: theme.bodyMedium?.copyWith(
|
|
|
|
|
color: textColor,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
const SizedBox(height: Spacing.xs),
|
2025-09-20 23:02:59 +05:30
|
|
|
Text(
|
|
|
|
|
subtitle,
|
2025-10-05 00:29:27 +05:30
|
|
|
style: theme.bodySmall?.copyWith(color: subtitleColor),
|
2025-09-20 23:02:59 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (trailing != null) ...[
|
2025-10-05 00:29:27 +05:30
|
|
|
const SizedBox(width: Spacing.sm),
|
2025-09-20 23:02:59 +05:30
|
|
|
trailing!,
|
|
|
|
|
] else if (showChevron && onTap != null) ...[
|
2025-10-05 00:29:27 +05:30
|
|
|
const SizedBox(width: Spacing.sm),
|
2025-09-20 23:02:59 +05:30
|
|
|
Icon(
|
|
|
|
|
UiUtils.platformIcon(
|
|
|
|
|
ios: CupertinoIcons.chevron_right,
|
|
|
|
|
android: Icons.chevron_right,
|
|
|
|
|
),
|
|
|
|
|
color: theme.iconSecondary,
|
|
|
|
|
size: IconSize.small,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
class _DefaultModelBottomSheet extends ConsumerStatefulWidget {
|
|
|
|
|
final List<Model> models;
|
|
|
|
|
final String? currentDefaultModelId;
|
|
|
|
|
|
|
|
|
|
const _DefaultModelBottomSheet({
|
|
|
|
|
required this.models,
|
|
|
|
|
required this.currentDefaultModelId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
2025-08-24 20:27:11 +05:30
|
|
|
ConsumerState<_DefaultModelBottomSheet> createState() =>
|
|
|
|
|
_DefaultModelBottomSheetState();
|
2025-08-17 17:01:06 +05:30
|
|
|
}
|
|
|
|
|
|
2025-08-24 20:27:11 +05:30
|
|
|
class _DefaultModelBottomSheetState
|
|
|
|
|
extends ConsumerState<_DefaultModelBottomSheet> {
|
2025-08-17 17:01:06 +05:30
|
|
|
final TextEditingController _searchController = TextEditingController();
|
|
|
|
|
String _searchQuery = '';
|
|
|
|
|
List<Model> _filteredModels = [];
|
|
|
|
|
Timer? _searchDebounce;
|
|
|
|
|
String? _selectedModelId;
|
|
|
|
|
|
|
|
|
|
Widget _capabilityChip({required IconData icon, required String label}) {
|
|
|
|
|
return Container(
|
|
|
|
|
margin: const EdgeInsets.only(right: Spacing.xs),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: Spacing.xs, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: context.conduitTheme.buttonPrimary.withValues(alpha: 0.08),
|
|
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.chip),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: context.conduitTheme.buttonPrimary.withValues(alpha: 0.3),
|
|
|
|
|
width: BorderWidth.thin,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(icon, size: 12, color: context.conduitTheme.buttonPrimary),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Text(
|
|
|
|
|
label,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: AppTypography.labelSmall,
|
|
|
|
|
color: context.conduitTheme.textSecondary,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-08-17 17:43:19 +05:30
|
|
|
// If no default model is set (null), default to auto-select
|
|
|
|
|
_selectedModelId = widget.currentDefaultModelId ?? 'auto-select';
|
2025-08-17 17:01:06 +05:30
|
|
|
// Add auto-select as first item
|
2025-09-19 21:12:15 +05:30
|
|
|
_filteredModels = _allModels();
|
2025-08-17 17:01:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_searchController.dispose();
|
|
|
|
|
_searchDebounce?.cancel();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 21:12:15 +05:30
|
|
|
List<Model> _allModels() {
|
|
|
|
|
return [
|
|
|
|
|
const Model(id: 'auto-select', name: 'Auto-select'),
|
|
|
|
|
...widget.models,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
void _filterModels(String query) {
|
2025-09-19 21:12:15 +05:30
|
|
|
setState(() => _searchQuery = query);
|
|
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
_searchDebounce?.cancel();
|
|
|
|
|
_searchDebounce = Timer(const Duration(milliseconds: 160), () {
|
2025-09-19 21:12:15 +05:30
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
|
|
final normalized = query.trim().toLowerCase();
|
|
|
|
|
final allModels = _allModels();
|
|
|
|
|
final filtered = normalized.isEmpty
|
|
|
|
|
? allModels
|
|
|
|
|
: allModels.where((model) {
|
|
|
|
|
final name = model.name.toLowerCase();
|
|
|
|
|
final id = model.id.toLowerCase();
|
|
|
|
|
return name.contains(normalized) || id.contains(normalized);
|
|
|
|
|
}).toList();
|
|
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
setState(() {
|
2025-09-19 21:12:15 +05:30
|
|
|
_filteredModels = filtered;
|
2025-08-17 17:01:06 +05:30
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-09-19 21:12:15 +05:30
|
|
|
return Stack(
|
|
|
|
|
children: [
|
|
|
|
|
Positioned.fill(
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
behavior: HitTestBehavior.opaque,
|
|
|
|
|
onTap: () => Navigator.of(context).maybePop(),
|
|
|
|
|
child: const SizedBox.shrink(),
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
),
|
|
|
|
|
DraggableScrollableSheet(
|
|
|
|
|
expand: false,
|
|
|
|
|
initialChildSize: 0.75,
|
|
|
|
|
maxChildSize: 0.92,
|
|
|
|
|
minChildSize: 0.45,
|
|
|
|
|
builder: (context, scrollController) {
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: context.sidebarTheme.background,
|
2025-09-19 21:12:15 +05:30
|
|
|
borderRadius: const BorderRadius.vertical(
|
|
|
|
|
top: Radius.circular(AppBorderRadius.bottomSheet),
|
|
|
|
|
),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: context.conduitTheme.dividerColor,
|
|
|
|
|
width: BorderWidth.regular,
|
|
|
|
|
),
|
2025-10-03 00:12:25 +05:30
|
|
|
boxShadow: ConduitShadows.modal(context),
|
2025-09-19 21:12:15 +05:30
|
|
|
),
|
|
|
|
|
child: ModalSheetSafeArea(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: Spacing.modalPadding,
|
|
|
|
|
vertical: Spacing.modalPadding,
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
// Handle bar (standardized)
|
|
|
|
|
const SheetHandle(),
|
|
|
|
|
|
|
|
|
|
// Header removed (no icon/title or save button)
|
|
|
|
|
const SizedBox(height: Spacing.md),
|
|
|
|
|
|
|
|
|
|
// Search field
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: Spacing.md),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _searchController,
|
|
|
|
|
style: AppTypography.standard.copyWith(
|
|
|
|
|
color: context.conduitTheme.textPrimary,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
onChanged: _filterModels,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
isDense: true,
|
|
|
|
|
hintText: AppLocalizations.of(context)!.searchModels,
|
|
|
|
|
hintStyle: AppTypography.standard.copyWith(
|
|
|
|
|
color: context.conduitTheme.inputPlaceholder,
|
2025-08-24 20:27:11 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
prefixIcon: Icon(
|
|
|
|
|
Platform.isIOS
|
|
|
|
|
? CupertinoIcons.search
|
|
|
|
|
: Icons.search,
|
|
|
|
|
color: context.conduitTheme.iconSecondary,
|
|
|
|
|
size: IconSize.input,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
prefixIconConstraints: const BoxConstraints(
|
|
|
|
|
minWidth: TouchTarget.minimum,
|
|
|
|
|
minHeight: TouchTarget.minimum,
|
2025-08-24 20:27:11 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
suffixIcon: _searchQuery.isNotEmpty
|
|
|
|
|
? IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_searchController.clear();
|
|
|
|
|
_filterModels('');
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Platform.isIOS
|
|
|
|
|
? CupertinoIcons.clear_circled_solid
|
|
|
|
|
: Icons.clear,
|
|
|
|
|
color: context.conduitTheme.iconSecondary,
|
|
|
|
|
size: IconSize.input,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: null,
|
|
|
|
|
suffixIconConstraints: const BoxConstraints(
|
|
|
|
|
minWidth: TouchTarget.minimum,
|
|
|
|
|
minHeight: TouchTarget.minimum,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
filled: true,
|
|
|
|
|
fillColor: context.conduitTheme.inputBackground,
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
|
AppBorderRadius.md,
|
|
|
|
|
),
|
|
|
|
|
borderSide: BorderSide.none,
|
2025-08-21 23:56:47 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
|
AppBorderRadius.md,
|
|
|
|
|
),
|
|
|
|
|
borderSide: BorderSide(
|
|
|
|
|
color: context.conduitTheme.inputBorder,
|
|
|
|
|
width: 1,
|
|
|
|
|
),
|
2025-08-24 20:27:11 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
focusedBorder: OutlineInputBorder(
|
2025-08-24 20:27:11 +05:30
|
|
|
borderRadius: BorderRadius.circular(
|
2025-09-19 21:12:15 +05:30
|
|
|
AppBorderRadius.md,
|
2025-08-24 20:27:11 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
borderSide: BorderSide(
|
|
|
|
|
color: context.conduitTheme.buttonPrimary,
|
|
|
|
|
width: 1,
|
2025-08-21 23:56:47 +05:30
|
|
|
),
|
|
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: Spacing.md,
|
|
|
|
|
vertical: Spacing.xs,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Section header (cohesive with Chats Drawer)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: Spacing.sm),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
AppLocalizations.of(context)!.availableModels,
|
2025-08-21 23:56:47 +05:30
|
|
|
style: AppTypography.bodySmallStyle.copyWith(
|
2025-09-19 21:12:15 +05:30
|
|
|
fontWeight: FontWeight.w600,
|
2025-08-21 23:56:47 +05:30
|
|
|
color: context.conduitTheme.textSecondary,
|
2025-09-19 21:12:15 +05:30
|
|
|
letterSpacing: 0.2,
|
2025-08-21 23:56:47 +05:30
|
|
|
),
|
|
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
const SizedBox(width: Spacing.xs),
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 6,
|
|
|
|
|
vertical: 2,
|
|
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
2025-10-18 13:58:15 +05:30
|
|
|
color: context.sidebarTheme.background.withValues(
|
|
|
|
|
alpha: 0.6,
|
|
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
|
AppBorderRadius.xs,
|
|
|
|
|
),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: context.conduitTheme.dividerColor,
|
|
|
|
|
width: BorderWidth.thin,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
'${_filteredModels.length}',
|
|
|
|
|
style: AppTypography.bodySmallStyle.copyWith(
|
|
|
|
|
color: context.conduitTheme.textSecondary,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-21 23:56:47 +05:30
|
|
|
),
|
|
|
|
|
|
2025-09-19 21:12:15 +05:30
|
|
|
const SizedBox(height: Spacing.sm),
|
|
|
|
|
|
|
|
|
|
// Models list
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Scrollbar(
|
|
|
|
|
controller: scrollController,
|
|
|
|
|
child: _filteredModels.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Platform.isIOS
|
|
|
|
|
? CupertinoIcons.search_circle
|
|
|
|
|
: Icons.search_off,
|
|
|
|
|
size: 48,
|
|
|
|
|
color: context.conduitTheme.iconSecondary,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
const SizedBox(height: Spacing.md),
|
|
|
|
|
Text(
|
|
|
|
|
AppLocalizations.of(context)!.noResults,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color:
|
|
|
|
|
context.conduitTheme.textSecondary,
|
|
|
|
|
fontSize: AppTypography.bodyLarge,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
controller: scrollController,
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
itemCount: _filteredModels.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final model = _filteredModels[index];
|
|
|
|
|
final isAutoSelect =
|
|
|
|
|
model.id == 'auto-select';
|
|
|
|
|
final isSelected = isAutoSelect
|
|
|
|
|
? _selectedModelId == null ||
|
|
|
|
|
_selectedModelId == 'auto-select'
|
|
|
|
|
: _selectedModelId == model.id;
|
|
|
|
|
|
|
|
|
|
return _buildModelListTile(
|
|
|
|
|
model: model,
|
|
|
|
|
isSelected: isSelected,
|
|
|
|
|
isAutoSelect: isAutoSelect,
|
|
|
|
|
onTap: () {
|
|
|
|
|
HapticFeedback.lightImpact();
|
|
|
|
|
final selectedId = isAutoSelect
|
|
|
|
|
? 'auto-select'
|
|
|
|
|
: model.id;
|
|
|
|
|
Navigator.pop(context, selectedId);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
),
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
],
|
|
|
|
|
),
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
2025-09-19 21:12:15 +05:30
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-08-17 17:01:06 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _modelSupportsReasoning(Model model) {
|
|
|
|
|
final params = model.supportedParameters ?? const [];
|
|
|
|
|
return params.any((p) => p.toLowerCase().contains('reasoning'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildModelListTile({
|
|
|
|
|
required Model model,
|
|
|
|
|
required bool isSelected,
|
|
|
|
|
required bool isAutoSelect,
|
|
|
|
|
required VoidCallback onTap,
|
|
|
|
|
}) {
|
2025-09-20 22:03:55 +05:30
|
|
|
final api = ref.watch(apiServiceProvider);
|
|
|
|
|
|
|
|
|
|
final Widget leading;
|
|
|
|
|
if (isAutoSelect) {
|
|
|
|
|
leading = Container(
|
|
|
|
|
width: 32,
|
|
|
|
|
height: 32,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: context.conduitTheme.buttonPrimary.withValues(alpha: 0.15),
|
|
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.md),
|
|
|
|
|
),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Platform.isIOS ? CupertinoIcons.wand_stars : Icons.auto_awesome,
|
|
|
|
|
color: context.conduitTheme.buttonPrimary,
|
|
|
|
|
size: 16,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
final iconUrl = resolveModelIconUrlForModel(api, model);
|
|
|
|
|
leading = ModelAvatar(size: 32, imageUrl: iconUrl, label: model.name);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-17 17:01:06 +05:30
|
|
|
return PressableScale(
|
|
|
|
|
onTap: onTap,
|
2025-10-05 00:33:42 +05:30
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.small),
|
2025-08-17 17:01:06 +05:30
|
|
|
child: Container(
|
2025-10-05 00:33:42 +05:30
|
|
|
margin: const EdgeInsets.only(bottom: Spacing.sm),
|
2025-08-17 17:01:06 +05:30
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: isSelected
|
2025-10-05 00:33:42 +05:30
|
|
|
? context.conduitTheme.buttonPrimary.withValues(alpha: 0.1)
|
2025-10-18 13:58:15 +05:30
|
|
|
: context.sidebarTheme.background.withValues(alpha: 0.05),
|
2025-10-05 00:33:42 +05:30
|
|
|
borderRadius: BorderRadius.circular(AppBorderRadius.small),
|
2025-08-17 17:01:06 +05:30
|
|
|
border: Border.all(
|
|
|
|
|
color: isSelected
|
2025-10-05 00:33:42 +05:30
|
|
|
? context.conduitTheme.buttonPrimary.withValues(alpha: 0.3)
|
|
|
|
|
: context.conduitTheme.dividerColor.withValues(alpha: 0.5),
|
|
|
|
|
width: BorderWidth.standard,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Padding(
|
2025-10-05 00:33:42 +05:30
|
|
|
padding: const EdgeInsets.all(Spacing.sm),
|
2025-08-17 17:01:06 +05:30
|
|
|
child: Row(
|
|
|
|
|
children: [
|
2025-09-20 22:03:55 +05:30
|
|
|
leading,
|
2025-10-05 00:33:42 +05:30
|
|
|
const SizedBox(width: Spacing.sm),
|
2025-08-17 17:01:06 +05:30
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
2025-08-24 20:27:11 +05:30
|
|
|
isAutoSelect
|
|
|
|
|
? AppLocalizations.of(context)!.autoSelect
|
|
|
|
|
: model.name,
|
2025-08-17 17:01:06 +05:30
|
|
|
style: TextStyle(
|
|
|
|
|
color: context.conduitTheme.textPrimary,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
fontSize: AppTypography.bodyMedium,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
if (isAutoSelect) ...[
|
|
|
|
|
const SizedBox(height: Spacing.xs),
|
|
|
|
|
Text(
|
2025-11-02 17:44:23 +05:30
|
|
|
AppLocalizations.of(context)!.autoSelectDescription,
|
2025-08-17 17:01:06 +05:30
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: AppTypography.bodySmall,
|
|
|
|
|
color: context.conduitTheme.textSecondary,
|
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-10-05 00:59:32 +05:30
|
|
|
] else if (model.isMultimodal ||
|
|
|
|
|
_modelSupportsReasoning(model)) ...[
|
2025-08-17 17:01:06 +05:30
|
|
|
const SizedBox(height: Spacing.xs),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
if (model.isMultimodal)
|
|
|
|
|
_capabilityChip(
|
|
|
|
|
icon: Platform.isIOS
|
|
|
|
|
? CupertinoIcons.photo
|
|
|
|
|
: Icons.image,
|
2025-11-02 17:44:23 +05:30
|
|
|
label: AppLocalizations.of(
|
|
|
|
|
context,
|
|
|
|
|
)!.modelCapabilityMultimodal,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
if (_modelSupportsReasoning(model))
|
|
|
|
|
_capabilityChip(
|
|
|
|
|
icon: Platform.isIOS
|
|
|
|
|
? CupertinoIcons.lightbulb
|
|
|
|
|
: Icons.psychology_alt,
|
2025-11-02 17:44:23 +05:30
|
|
|
label: AppLocalizations.of(
|
|
|
|
|
context,
|
|
|
|
|
)!.modelCapabilityReasoning,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-10-05 00:33:42 +05:30
|
|
|
const SizedBox(width: Spacing.sm),
|
|
|
|
|
if (isSelected)
|
|
|
|
|
Icon(
|
|
|
|
|
Platform.isIOS ? CupertinoIcons.check_mark : Icons.check,
|
|
|
|
|
color: context.conduitTheme.buttonPrimary,
|
|
|
|
|
size: IconSize.small,
|
2025-08-17 17:01:06 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-10-05 00:29:27 +05:30
|
|
|
);
|
2025-08-17 17:01:06 +05:30
|
|
|
}
|
|
|
|
|
}
|