@@ -4,29 +4,38 @@ import 'package:flutter/cupertino.dart';
44import 'package:flutter/material.dart' ;
55import 'package:flutter/services.dart' ;
66import 'package:flutter_swipe_action_cell/flutter_swipe_action_cell.dart' ;
7+ import 'package:oshi/interface/components/cupertino/widgets/options_form.dart' ;
8+ import 'package:oshi/interface/components/shim/modal_page.dart' ;
9+ import 'package:oshi/interface/components/shim/page_routes.dart' ;
710import 'package:oshi/interface/shared/containers.dart' ;
11+ import 'package:oshi/interface/shared/input.dart' ;
812import 'package:oshi/share/share.dart' ;
913
1014class EntriesForm <T > extends StatefulWidget {
11- const EntriesForm (
12- {super .key,
13- this .header = '' ,
14- this .description = '' ,
15- this .placeholder = 'Key' ,
16- required this .update,
17- required this .validate,
18- this .maxKeyLength = 3 ,
19- this .maxValueLength = 5 });
15+ const EntriesForm ({
16+ super .key,
17+ this .header = '' ,
18+ this .description = '' ,
19+ this .placeholder = 'Key' ,
20+ required this .update,
21+ required this .validate,
22+ this .maxKeyLength = 3 ,
23+ this .maxValueLength = 5 ,
24+ this .options,
25+ this .noOption = 'Select' ,
26+ });
2027
2128 final String header;
2229 final String description;
2330 final String placeholder;
31+ final String noOption;
2432
2533 final int maxKeyLength;
2634 final int maxValueLength;
2735
2836 final Map <String , T > Function <T >([Map <String , T >? ]) update;
2937 final T ? Function (String ) validate;
38+ final List <String >? options;
3039
3140 @override
3241 State <EntriesForm > createState () => _EntriesFormState ();
@@ -78,6 +87,7 @@ class _EntriesFormState<T> extends State<EntriesForm<T>> {
7887 // The 'add' menu
7988 .append (AdaptiveCard (
8089 regular: true ,
90+ hideChevron: true ,
8191 click: () {
8292 var result = widget.validate (_valueController.text);
8393 if (! (_keyController.text.isNotEmpty &&
@@ -115,31 +125,81 @@ class _EntriesFormState<T> extends State<EntriesForm<T>> {
115125 child: Row (
116126 mainAxisAlignment: MainAxisAlignment .spaceBetween,
117127 children: [
118- ConstrainedBox (
119- constraints: BoxConstraints (maxWidth: 50 ),
120- child: Share .settings.appSettings.useCupertino
121- ? CupertinoTextField (
122- onChanged: (value) => setState (() {}),
123- controller: _keyController,
124- expands: false ,
125- textAlign: TextAlign .start,
126- maxLength: widget.maxKeyLength,
127- maxLengthEnforcement: MaxLengthEnforcement .enforced)
128- : TextFormField (
129- onChanged: (value) => setState (() {}),
130- controller: _keyController,
131- expands: false ,
132- textAlign: TextAlign .start,
133- maxLength: widget.maxKeyLength,
134- maxLengthEnforcement: MaxLengthEnforcement .enforced,
135- decoration: InputDecoration (
136- counterText: "" ,
137- errorBorder: InputBorder .none,
138- disabledBorder: InputBorder .none,
139- hintTextDirection: TextDirection .ltr,
140- fillColor: Colors .transparent,
128+ if (widget.options? .isEmpty ?? true )
129+ ConstrainedBox (
130+ constraints: BoxConstraints (maxWidth: 50 ),
131+ child: Share .settings.appSettings.useCupertino
132+ ? CupertinoTextField (
133+ onChanged: (value) => setState (() {}),
134+ controller: _keyController,
135+ expands: false ,
136+ textAlign: TextAlign .start,
137+ maxLength: widget.maxKeyLength,
138+ maxLengthEnforcement: MaxLengthEnforcement .enforced)
139+ : TextFormField (
140+ onChanged: (value) => setState (() {}),
141+ controller: _keyController,
142+ expands: false ,
143+ textAlign: TextAlign .start,
144+ maxLength: widget.maxKeyLength,
145+ maxLengthEnforcement: MaxLengthEnforcement .enforced,
146+ decoration: InputDecoration (
147+ counterText: "" ,
148+ errorBorder: InputBorder .none,
149+ disabledBorder: InputBorder .none,
150+ hintTextDirection: TextDirection .ltr,
151+ fillColor: Colors .transparent,
152+ ),
153+ )),
154+ if (widget.options? .isNotEmpty ?? false )
155+ Share .settings.appSettings.useCupertino
156+ ? CupertinoButton (
157+ padding: EdgeInsets .only (top: 5 , bottom: 5 , right: 10 ),
158+ child: ConstrainedBox (
159+ constraints: BoxConstraints (maxWidth: 150 ),
160+ child: Text (
161+ _keyController.text.isNotEmpty ? _keyController.text : widget.noOption,
162+ maxLines: 1 ,
163+ overflow: TextOverflow .ellipsis,
141164 ),
142- )),
165+ ),
166+ onPressed: () => Navigator .push (
167+ context,
168+ AdaptivePageRoute (
169+ builder: (context) => ModalPageBase .adaptive (title: widget.noOption, children: [
170+ OptionsForm (
171+ selection: _keyController.text,
172+ options: widget.options!
173+ .select ((x, _) => OptionEntry (name: x, value: x))
174+ .toList (),
175+ update: < T > (v) {
176+ _keyController.text = v;
177+ setState (() {});
178+ })
179+ ]))))
180+ : ElevatedButton (
181+ style: ElevatedButton .styleFrom (
182+ backgroundColor: Theme .of (context).colorScheme.secondary,
183+ padding: EdgeInsets .symmetric (horizontal: 15 , vertical: 13 )),
184+ onPressed: () => showOptionDialog (
185+ context: context,
186+ scrollable: true ,
187+ title: widget.noOption,
188+ icon: Icons .list,
189+ selection: _keyController.text,
190+ options: widget.options! .select ((x, _) => OptionEntry (name: x, value: x)).toList (),
191+ onChanged: (v) {
192+ _keyController.text = v;
193+ setState (() {});
194+ }),
195+ child: ConstrainedBox (
196+ constraints: BoxConstraints (maxWidth: 125 ),
197+ child: Text (_keyController.text.isNotEmpty ? _keyController.text : widget.noOption,
198+ maxLines: 1 ,
199+ overflow: TextOverflow .ellipsis,
200+ style: TextStyle (fontSize: 15 , color: Theme .of (context).colorScheme.onSecondary)),
201+ ),
202+ ),
143203 ConstrainedBox (
144204 constraints: BoxConstraints (maxWidth: _valueController.text.isNotEmpty ? 70 : 100 ),
145205 child: Share .settings.appSettings.useCupertino
0 commit comments