98 lines
2.7 KiB
Dart
98 lines
2.7 KiB
Dart
import 'package:capstone_project/providers/settings.dart';
|
|
import 'package:capstone_project/widgets/app_shell.dart';
|
|
import 'package:capstone_project/widgets/panel_layout.dart';
|
|
import 'package:file_picker/file_picker.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
|
|
|
|
|
class SettingsPage extends StatefulWidget {
|
|
static GoRoute route = GoRoute(
|
|
path: "/settings",
|
|
builder: (context, state) => SettingsPage(),
|
|
);
|
|
|
|
@override
|
|
State<SettingsPage> createState() => _SettingsPageState();
|
|
}
|
|
|
|
class _SettingsPageState extends State<SettingsPage> {
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final settings = SettingsProvider.of(context);
|
|
final apiKey = settings.openRouterApiKey;
|
|
final storagePath = settings.applicationStorageLocation;
|
|
|
|
final fields = <PanelField>[
|
|
|
|
PanelField(
|
|
section: 'API',
|
|
label: const Text('OpenRouter key'),
|
|
child: TextField(
|
|
placeholder: const Text('sk-or-...'),
|
|
initialValue: apiKey.isEmpty
|
|
? ''
|
|
: '${apiKey.substring(0, apiKey.length >= 8 ? 8 : apiKey.length)}xxxxxx',
|
|
onChanged: (value) => settings.setOpenRouterApiKey(value),
|
|
),
|
|
),
|
|
|
|
PanelField(
|
|
section: 'Application Data',
|
|
label: const Text('Storage path'),
|
|
child: Row(
|
|
children: [
|
|
|
|
Expanded(
|
|
child: Text(
|
|
storagePath.isEmpty ? 'Default' : storagePath,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
color: Theme.of(context).colorScheme.mutedForeground,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
|
|
const Gap(8),
|
|
|
|
Button.outline(
|
|
onPressed: () {
|
|
FilePicker.platform.getDirectoryPath().then((path) {
|
|
if (path != null) {
|
|
settings.setApplicationStorageLocation(path);
|
|
setState(() {});
|
|
}
|
|
});
|
|
},
|
|
child: const Text('Browse'),
|
|
),
|
|
|
|
const Gap(4),
|
|
|
|
IconButton.destructive(
|
|
icon: const Icon(LucideIcons.refreshCcw),
|
|
onPressed: () async {
|
|
final dir = await getApplicationDocumentsDirectory();
|
|
settings.setApplicationStorageLocation(dir.path);
|
|
setState(() {});
|
|
},
|
|
),
|
|
|
|
],
|
|
),
|
|
),
|
|
|
|
];
|
|
|
|
return AugorShell(
|
|
titleTag: 'Settings',
|
|
statusLeft: const StatusText('Augor · Settings'),
|
|
child: SingleChildScrollView(
|
|
child: PanelList(fields: fields),
|
|
),
|
|
);
|
|
}
|
|
}
|