98 lines
2.9 KiB
Dart
98 lines
2.9 KiB
Dart
import 'package:cutdex_native/cutdex_native.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../app/shells/desktop_window_frame.dart';
|
|
import '../../app/adaptive/desktop_content_controller.dart';
|
|
import '../../integrations/platform/device_experience.dart';
|
|
import '../../integrations/platform/editor_window_chrome.dart';
|
|
import '../../l10n/l10n.dart';
|
|
import 'settings_content.dart';
|
|
|
|
Future<void> showSettingsPage(
|
|
BuildContext context, {
|
|
(String, String)? workspace,
|
|
int? initialTab,
|
|
}) {
|
|
final container = ProviderScope.containerOf(context, listen: false);
|
|
if (container.read(deviceExperienceProvider) == DeviceExperience.desktop) {
|
|
container
|
|
.read(desktopContentProvider.notifier)
|
|
.showSettings(tab: initialTab, workspace: workspace);
|
|
return Future<void>.value();
|
|
}
|
|
return context.push<void>(
|
|
'/settings?tab=${initialTab ?? 0}',
|
|
extra: workspace,
|
|
);
|
|
}
|
|
|
|
/// A pushed route keeps the editor and its session mounted underneath.
|
|
class SettingsPage extends ConsumerWidget {
|
|
const SettingsPage({super.key, this.workspace, this.initialTab = 0});
|
|
final (String, String)? workspace;
|
|
final int initialTab;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final desktop =
|
|
ref.watch(deviceExperienceProvider) == DeviceExperience.desktop;
|
|
void back() {
|
|
if (context.canPop()) {
|
|
context.pop();
|
|
} else {
|
|
context.go('/');
|
|
}
|
|
}
|
|
|
|
final content = SettingsContent(
|
|
workspace: workspace,
|
|
initialTab: initialTab,
|
|
);
|
|
if (!desktop) {
|
|
return Scaffold(
|
|
key: const Key('settings-page'),
|
|
appBar: AppBar(
|
|
leading: BackButton(
|
|
key: const Key('settings-page-back'),
|
|
onPressed: back,
|
|
),
|
|
title: Text(context.l10n.settings),
|
|
),
|
|
body: content,
|
|
);
|
|
}
|
|
return EditorWindowChrome(
|
|
headerHeight: DesktopWindowFrame.headerHeight,
|
|
builder: (context, integrated) => Scaffold(
|
|
key: const Key('settings-page'),
|
|
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
|
body: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: DesktopWindowFrame.headerHeight,
|
|
child: WindowHeaderPadding(
|
|
child: Row(
|
|
children: [
|
|
if (integrated)
|
|
SizedBox(width: EditorWindowChrome.leadingWidth),
|
|
HeaderControlRegion(
|
|
child: BackButton(
|
|
key: const Key('settings-page-back'),
|
|
onPressed: back,
|
|
),
|
|
),
|
|
Text(context.l10n.settings),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Expanded(child: content),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|