add room access settings
This commit is contained in:
parent
8e51852ae3
commit
b390dbbbe1
1 changed files with 974 additions and 128 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import "dart:async";
|
||||
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/helpers/hooks/saving.dart";
|
||||
import "package:nexus/widgets/sheet_layout.dart";
|
||||
|
||||
class const TextSettingTile({
|
||||
|
|
@ -9,54 +12,59 @@ class const TextSettingTile({
|
|||
required final String description,
|
||||
required final String? value,
|
||||
|
||||
/// Disables the tile if null
|
||||
required final void Function(String value)? onChanged,
|
||||
/// Disables the tile if null, and while a returned future runs.
|
||||
required final FutureOr<void> Function(String value)? onChanged,
|
||||
final bool multiline = false,
|
||||
super.key,
|
||||
}) extends StatelessWidget {
|
||||
}) extends HookWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => ListTile(
|
||||
enabled: onChanged != null,
|
||||
leading: icon,
|
||||
title: Text(title),
|
||||
subtitle: Text(
|
||||
value?.isNotEmpty == true ? value! : description,
|
||||
maxLines: 2,
|
||||
overflow: .ellipsis,
|
||||
),
|
||||
onTap: () => context.showAdaptiveSheet(
|
||||
(context) => HookBuilder(
|
||||
builder: (context) {
|
||||
final controller = useTextEditingController(text: value);
|
||||
Widget build(BuildContext context) {
|
||||
final saving = Saving.use();
|
||||
Future<void> change(String value) => saving.run(() => onChanged!(value));
|
||||
|
||||
void save() {
|
||||
Navigator.of(context).pop();
|
||||
onChanged!(controller.text.trim());
|
||||
}
|
||||
|
||||
return SheetLayout(
|
||||
title: Text(title),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
TextButton(onPressed: save, child: Text("Save")),
|
||||
],
|
||||
children: [
|
||||
TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
textCapitalization: .sentences,
|
||||
minLines: 1,
|
||||
maxLines: multiline ? 6 : 1,
|
||||
onSubmitted: multiline ? null : (_) => save(),
|
||||
decoration: .new(labelText: title),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
return ListTile(
|
||||
enabled: onChanged != null && !saving.active,
|
||||
leading: icon,
|
||||
title: Text(title),
|
||||
subtitle: Text(
|
||||
value?.isNotEmpty == true ? value! : description,
|
||||
maxLines: 2,
|
||||
overflow: .ellipsis,
|
||||
),
|
||||
),
|
||||
);
|
||||
onTap: () => context.showAdaptiveSheet(
|
||||
(context) => HookBuilder(
|
||||
builder: (context) {
|
||||
final controller = useTextEditingController(text: value);
|
||||
|
||||
void save() {
|
||||
Navigator.of(context).pop();
|
||||
change(controller.text.trim());
|
||||
}
|
||||
|
||||
return SheetLayout(
|
||||
title: Text(title),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
TextButton(onPressed: save, child: Text("Save")),
|
||||
],
|
||||
children: [
|
||||
TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
textCapitalization: .sentences,
|
||||
minLines: 1,
|
||||
maxLines: multiline ? 6 : 1,
|
||||
onSubmitted: multiline ? null : (_) => save(),
|
||||
decoration: .new(labelText: title),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue