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:flutter/material.dart'; |
||||||
import 'package:intersperse/intersperse.dart'; |
|
||||||
import 'package:meta/meta.dart'; |
import 'package:meta/meta.dart'; |
||||||
import 'package:neon/src/settings/widgets/settings_tile.dart'; |
import 'package:neon/src/utils/adaptive.dart'; |
||||||
|
|
||||||
@internal |
@internal |
||||||
class SettingsCategory extends StatelessWidget { |
class SettingsCategory extends StatelessWidget { |
||||||
const SettingsCategory({ |
const SettingsCategory({ |
||||||
required this.tiles, |
required this.tiles, |
||||||
this.title, |
this.title, |
||||||
|
this.footer, |
||||||
|
this.hasLeading = false, |
||||||
super.key, |
super.key, |
||||||
}); |
}); |
||||||
|
|
||||||
final Widget? title; |
final Widget? title; |
||||||
final List<SettingsTile> tiles; |
final List<Widget> tiles; |
||||||
|
final Widget? footer; |
||||||
|
final bool hasLeading; |
||||||
|
|
||||||
@override |
@override |
||||||
Widget build(final BuildContext context) { |
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; |
final textTheme = Theme.of(context).textTheme; |
||||||
|
|
||||||
return Column( |
return Column( |
||||||
crossAxisAlignment: CrossAxisAlignment.start, |
crossAxisAlignment: CrossAxisAlignment.start, |
||||||
children: [ |
children: [ |
||||||
if (title != null) |
if (header != null) |
||||||
DefaultTextStyle( |
Padding( |
||||||
style: textTheme.titleMedium!.copyWith( |
padding: const EdgeInsets.only(top: 25, bottom: 5), |
||||||
fontWeight: FontWeight.bold, |
child: DefaultTextStyle( |
||||||
|
style: textTheme.titleMedium!.copyWith( |
||||||
|
color: theme.colorScheme.secondary, |
||||||
|
fontWeight: FontWeight.bold, |
||||||
|
), |
||||||
|
child: header!, |
||||||
), |
), |
||||||
child: title!, |
|
||||||
), |
), |
||||||
...tiles, |
...children, |
||||||
] |
], |
||||||
.intersperse( |
|
||||||
const SizedBox( |
|
||||||
height: 10, |
|
||||||
), |
|
||||||
) |
|
||||||
.toList(), |
|
||||||
); |
); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -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