Nikolas Rimikis
1 year ago
10 changed files with 605 additions and 391 deletions
@ -1,53 +0,0 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:meta/meta.dart'; |
||||
import 'package:neon/src/settings/models/option.dart'; |
||||
import 'package:neon/src/settings/widgets/settings_tile.dart'; |
||||
|
||||
@internal |
||||
class SelectSettingsTile<T> extends InputSettingsTile<SelectOption<T>> { |
||||
const SelectSettingsTile({ |
||||
required super.option, |
||||
super.key, |
||||
}); |
||||
|
||||
@override |
||||
Widget build(final BuildContext context) => ValueListenableBuilder( |
||||
valueListenable: option, |
||||
builder: (final context, final value, final child) => LayoutBuilder( |
||||
builder: (final context, final constraints) => ListTile( |
||||
enabled: option.enabled, |
||||
title: child, |
||||
trailing: ConstrainedBox( |
||||
constraints: BoxConstraints( |
||||
maxWidth: constraints.maxWidth * 0.5, |
||||
), |
||||
child: IntrinsicWidth( |
||||
child: DropdownButton<T>( |
||||
isExpanded: true, |
||||
value: value, |
||||
items: option.values.keys |
||||
.map( |
||||
(final k) => DropdownMenuItem( |
||||
value: k, |
||||
child: Text( |
||||
option.values[k]!(context), |
||||
overflow: TextOverflow.ellipsis, |
||||
), |
||||
), |
||||
) |
||||
.toList(), |
||||
onChanged: option.enabled |
||||
? (final value) { |
||||
option.value = value as T; |
||||
} |
||||
: null, |
||||
), |
||||
), |
||||
), |
||||
), |
||||
), |
||||
child: Text( |
||||
option.label(context), |
||||
), |
||||
); |
||||
} |
@ -1,41 +1,72 @@
|
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:intersperse/intersperse.dart'; |
||||
import 'package:meta/meta.dart'; |
||||
import 'package:neon/src/settings/widgets/settings_tile.dart'; |
||||
import 'package:neon/src/utils/adaptive.dart'; |
||||
|
||||
@internal |
||||
class SettingsCategory extends StatelessWidget { |
||||
const SettingsCategory({ |
||||
required this.tiles, |
||||
this.title, |
||||
this.footer, |
||||
this.hasLeading = false, |
||||
super.key, |
||||
}); |
||||
|
||||
final Widget? title; |
||||
final List<SettingsTile> tiles; |
||||
final List<Widget> tiles; |
||||
final Widget? footer; |
||||
final bool hasLeading; |
||||
|
||||
@override |
||||
Widget build(final BuildContext context) { |
||||
if (isCupertino(context)) { |
||||
return CupertinoListSection.insetGrouped( |
||||
hasLeading: hasLeading, |
||||
header: title, |
||||
footer: footer, |
||||
children: tiles, |
||||
); |
||||
} else { |
||||
return MaterialSettingsCategory( |
||||
header: title, |
||||
children: tiles, |
||||
); |
||||
} |
||||
} |
||||
} |
||||
|
||||
class MaterialSettingsCategory extends StatelessWidget { |
||||
const MaterialSettingsCategory({ |
||||
required this.children, |
||||
this.header, |
||||
super.key, |
||||
}); |
||||
|
||||
final Widget? header; |
||||
final List<Widget> children; |
||||
|
||||
@override |
||||
Widget build(final BuildContext context) { |
||||
final theme = Theme.of(context); |
||||
final textTheme = Theme.of(context).textTheme; |
||||
|
||||
return Column( |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
children: [ |
||||
if (title != null) |
||||
DefaultTextStyle( |
||||
if (header != null) |
||||
Padding( |
||||
padding: const EdgeInsets.only(top: 25, bottom: 5), |
||||
child: DefaultTextStyle( |
||||
style: textTheme.titleMedium!.copyWith( |
||||
color: theme.colorScheme.secondary, |
||||
fontWeight: FontWeight.bold, |
||||
), |
||||
child: title!, |
||||
child: header!, |
||||
), |
||||
...tiles, |
||||
] |
||||
.intersperse( |
||||
const SizedBox( |
||||
height: 10, |
||||
), |
||||
) |
||||
.toList(), |
||||
...children, |
||||
], |
||||
); |
||||
} |
||||
} |
||||
|
@ -1,23 +0,0 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:meta/meta.dart'; |
||||
import 'package:neon/src/settings/models/option.dart'; |
||||
import 'package:neon/src/settings/widgets/settings_tile.dart'; |
||||
|
||||
@internal |
||||
class ToggleSettingsTile extends InputSettingsTile<ToggleOption> { |
||||
const ToggleSettingsTile({ |
||||
required super.option, |
||||
super.key, |
||||
}); |
||||
|
||||
@override |
||||
Widget build(final BuildContext context) => ValueListenableBuilder( |
||||
valueListenable: option, |
||||
builder: (final context, final value, final child) => SwitchListTile.adaptive( |
||||
title: child, |
||||
value: value, |
||||
onChanged: option.enabled ? (final value) => option.value = value : null, |
||||
), |
||||
child: Text(option.label(context)), |
||||
); |
||||
} |
Loading…
Reference in new issue