Skip to content

Commit

Permalink
Re-work trigger select to use bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 1, 2024
1 parent 7c5466f commit 4778501
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 98 deletions.
77 changes: 0 additions & 77 deletions lib/Frontend/Widgets/trigger_select.dart

This file was deleted.

56 changes: 42 additions & 14 deletions lib/Frontend/pages/triggers.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:choice/choice.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:multi_value_listenable_builder/multi_value_listenable_builder.dart';
import 'package:tail_app/Backend/Definitions/Action/base_action.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/Backend/sensors.dart';
import 'package:tail_app/Frontend/Widgets/trigger_select.dart';
import 'package:uuid/uuid.dart';

import '../../constants.dart';
Expand All @@ -27,20 +27,42 @@ class _TriggersState extends ConsumerState<Triggers> {
Widget build(BuildContext context) {
final List<Trigger> triggersList = ref.watch(triggerListProvider);
return Scaffold(
floatingActionButton: FloatingActionButton.extended(
icon: const Icon(Icons.add),
onPressed: () {
showDialog<TriggerDefinition>(
context: context,
useRootNavigator: true,
builder: (BuildContext context) {
plausible.event(page: "/Triggers/AddTrigger");
return const TriggerSelect();
floatingActionButton: Builder(
builder: (context) {
List<TriggerDefinition> triggerDefinitions = ref.watch(triggerDefinitionListProvider.notifier).get();
return PromptedChoice<TriggerDefinition>.single(
itemCount: triggerDefinitions.length,
itemBuilder: (ChoiceController<TriggerDefinition> state, int index) {
TriggerDefinition triggerDefinition = triggerDefinitions[index];
return RadioListTile(
value: triggerDefinition,
groupValue: state.single,
onChanged: (value) {
state.select(triggerDefinition);
},
secondary: triggerDefinition.icon,
subtitle: ChoiceText(
triggerDefinition.description,
highlight: state.search?.value,
),
title: ChoiceText(
triggerDefinition.name,
highlight: state.search?.value,
),
);
},
).then(
(TriggerDefinition? value) {
promptDelegate: ChoicePrompt.delegateBottomSheet(useRootNavigator: true, enableDrag: true, maxHeightFactor: 0.8),
modalHeaderBuilder: ChoiceModal.createHeader(
automaticallyImplyLeading: true,
actionsBuilder: [
ChoiceModal.createConfirmButton(),
ChoiceModal.createSpacer(width: 10),
],
),
title: triggersSelectLabel(),
confirmation: true,
onChanged: (value) {
if (value != null) {
// The user selected a Trigger Definition
setState(
() {
Trigger trigger = Trigger.trigDef(value, const Uuid().v4());
Expand All @@ -50,9 +72,15 @@ class _TriggersState extends ConsumerState<Triggers> {
);
}
},
anchorBuilder: (state, openModal) {
return FloatingActionButton.extended(
icon: const Icon(Icons.add),
label: Text(triggersAdd()),
onPressed: openModal,
);
},
);
},
label: Text(triggersAdd()),
),
body: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
Expand Down
13 changes: 7 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: "6bd38d335f0954f5fad9c79e614604fbf03a0e5b975923dd001b6ea965ef5b4b"
sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d
url: "https://pub.dev"
source: hosted
version: "3.6.0"
version: "3.6.1"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -217,10 +217,11 @@ packages:
choice:
dependency: "direct main"
description:
name: choice
sha256: "52d07065e8056beba5b26cff7786134cbfa24927b1f5bf60a05d50058597b2d9"
url: "https://pub.dev"
source: hosted
path: "."
ref: HEAD
resolved-ref: ba4dc8b3579620e3fac0944dcab97f9b22e7c3eb
url: "https://github.com/Codel1417/flutter_choice"
source: git
version: "2.3.2"
circular_buffer:
dependency: "direct main"
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ dependencies:
flutter_native_splash: ^2.4.0
lottie_native: ^0.1.3
duration: ^3.0.13
choice: ^2.3.2 # used for device choice ui
choice:
git:
url: https://github.com/Codel1417/flutter_choice

# Dio HTTP
dio: ^5.4.3+1
Expand Down

0 comments on commit 4778501

Please sign in to comment.