import 'package:flutter/material.dart'; import 'package:flutter_flow_chart/flutter_flow_chart.dart'; import 'package:oc_front/core/services/specialized_services/abstract_service.dart'; import 'package:oc_front/models/abstract.dart'; import 'package:oc_front/models/response.dart'; abstract class New { String name = ""; } class NewBoxWidget> extends StatefulWidget { String? _selected; Dashboard dash; final TextEditingController _ctrl = TextEditingController(); AbstractService service; Function validate = () {}; NewBoxWidget ({ super.key, required this.service, required this.dash, this.getItems }); @override NewBoxWidgetState createState() => NewBoxWidgetState(); List Function(APIResponse? data)? getItems; } class NewBoxWidgetState> extends State { @override Widget build(BuildContext context) { widget._ctrl.value = TextEditingValue(text: widget.dash.defaultName); return Container( color: Colors.white, padding: const EdgeInsets.all(20), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children : [ FutureBuilder>( future: (widget.service as AbstractService).all(context), builder: (context, snapshot) { List items = widget.getItems != null ? widget.getItems!(snapshot.data) : []; if (widget._selected != null && !items.where((element) => element.value == widget._selected).isNotEmpty) { items.add(DropdownMenuItem( value: widget._selected.toString(), child: Text(widget._selected.toString()), )); } return SizedBox( width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 140 : 400, height: 50, child: DropdownButtonFormField( value: widget._selected, isExpanded: true, hint: const Text("load workflow...", style: TextStyle(color: Colors.grey, fontSize: 15)), decoration: InputDecoration( filled: true, focusedBorder: const OutlineInputBorder( borderRadius: BorderRadius.zero, borderSide: BorderSide(color: Color.fromARGB(38, 166, 154, 1), width: 0), ), fillColor: Colors.grey.shade300, contentPadding: const EdgeInsets.only(left: 30, right: 30, top: 10, bottom: 30), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.zero, borderSide: BorderSide(color: Colors.grey.shade300, width: 0), ), border: OutlineInputBorder( borderRadius: BorderRadius.zero, borderSide: BorderSide(color: Colors.grey.shade300, width: 0)), ), items: items, onChanged: (value) { setState(() { widget._selected = value.toString(); }); })); }), Tooltip( message: 'empty selection', child: InkWell( mouseCursor: widget._selected == null || widget._selected!.isEmpty ? MouseCursor.defer : SystemMouseCursors.click, onTap: () { if (widget._selected == null || widget._selected!.isEmpty) { return; } setState(() { widget._selected = null; }); }, child: Container( width: 50, height: 50, decoration: const BoxDecoration( color: Colors.black, border: Border(right: BorderSide(color: Colors.white))), child: Icon(Icons.refresh, color: widget._selected == null || widget._selected!.isEmpty ? Colors.grey : Colors.white), ) ) ), Tooltip( message: 'load workflow selected', child: InkWell( mouseCursor: widget._selected == null || widget._selected!.isEmpty ? MouseCursor.defer : SystemMouseCursors.click, onTap: () { if (widget._selected == null || widget._selected!.isEmpty) { return; } widget.dash.name = widget._selected ?? widget.dash.name; widget.dash.notifyListeners(); Navigator.pop(context); }, child: Container( width: 50, height: 50, color: Colors.black, child: Icon(Icons.open_in_browser_outlined, color: widget._selected == null || widget._selected!.isEmpty ? Colors.grey : Colors.white), ) ) ) ]), Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( margin: const EdgeInsets.only(top: 10), width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 90 : 450, height: 50, child: TextFormField( expands: true, maxLines: null, minLines: null, cursorColor: const Color.fromARGB(38, 166, 154, 1), controller: widget._ctrl, onChanged: (value) => setState(() { widget._ctrl.value = TextEditingValue(text: value); }), validator: (value) => value == null || value.isEmpty ? "name is required" : null, decoration: InputDecoration( hintText: "name a new workflow...", fillColor: Colors.grey.shade300, filled: true, contentPadding: const EdgeInsets.only(left: 30, right: 30, top: 15, bottom: 5), hintStyle: const TextStyle( color: Colors.black, fontSize: 14, fontWeight: FontWeight.w300 ), border: InputBorder.none ) ) ), Tooltip( message: 'add', child:InkWell( mouseCursor: widget._ctrl.value.text.isEmpty ? MouseCursor.defer : SystemMouseCursors.click, onTap: () async { if (widget._ctrl.value.text.isNotEmpty) { await widget.service.post(context, {}, { "workflowName" : widget._ctrl.value.text }); widget._selected = widget._ctrl.value.text; widget._ctrl.value = const TextEditingValue(text: ""); widget.dash.name = widget._selected ?? widget.dash.name; widget.dash.notifyListeners(); // ignore: use_build_context_synchronously Navigator.pop(context); } }, child: Container( margin: const EdgeInsets.only(top: 10), width: 50, height: 50, color: Colors.black, child: Icon(Icons.add, color: widget._ctrl.value.text.isEmpty ? Colors.grey : Colors.white) ) ) ) ]) ] ) ); } }