Skip to content

Commit

Permalink
Better config page selector
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Oct 31, 2024
1 parent e6a891a commit 96f3ca3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 38 deletions.
98 changes: 60 additions & 38 deletions lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:alic/config.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:signals/signals_flutter.dart';

import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart';
import 'src/rust/api/compressor.dart';

enum SettingsPages {
Expand All @@ -29,43 +29,65 @@ class _SettingsWidgetState extends State<SettingsWidget> {
@override
Widget build(BuildContext context) {
return Dialog(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(children: [
SegmentedButton(
selectedIcon: Container(),
onSelectionChanged: (p0) {
final newPage = SettingsPages.values.firstWhere(
(element) => element.toString() == p0.first.toString());
setState(() {
_selectedPage = newPage;
});
},
segments: SettingsPages.values
.map((e) =>
ButtonSegment(value: e.toString(), label: Text(e.title)))
.toList(),
selected: <dynamic>{_selectedPage.toString()},
),
const SizedBox(height: 10),
_getSelectedPage(),
const Spacer(),
Row(
children: [
TextButton(
onPressed: () {
Config.reset();
},
child: const Text('Reset')),
const Spacer(),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close')),
],
)
]),
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
var nextPage = SettingsPages.values[
(SettingsPages.values.indexOf(_selectedPage) + 1) %
SettingsPages.values.length];
if (event.logicalKey == LogicalKeyboardKey.tab) {
setState(() {
_selectedPage = nextPage;
});
}
},
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(children: [
CustomSlidingSegmentedControl<SettingsPages>(
initialValue: _selectedPage,
clipBehavior: Clip.antiAlias,
children: SettingsPages.values.fold({}, (map, element) {
map[element] = Text(element.title);
return map;
}),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(16),
),
thumbDecoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(16),
),
customSegmentSettings: CustomSegmentSettings(
borderRadius: BorderRadius.circular(25),
),
onValueChanged: (newPage) {
setState(() {
_selectedPage = newPage;
});
},
),
const SizedBox(height: 10),
_getSelectedPage(),
const Spacer(),
Row(
children: [
TextButton(
onPressed: () {
Config.reset();
},
child: const Text('Reset')),
const Spacer(),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close')),
],
)
]),
),
),
);
}
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.14"
custom_sliding_segmented_control:
dependency: "direct main"
description:
name: custom_sliding_segmented_control
sha256: "53c3e931c3ae1f696085d1ec70ac8e934da836595a9b7d9b88fdd0fcbf2a5574"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
dart_style:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies:
package_info_plus: ^8.0.0
http: ^1.2.1
url_launcher: ^6.2.6
custom_sliding_segmented_control: ^1.8.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 96f3ca3

Please sign in to comment.