199 lines
10 KiB
Dart
199 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
|
|
import 'package:oc_front/core/models/workspace_local.dart';
|
|
import 'package:oc_front/core/services/router.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<T extends SerializerDeserializer<dynamic>> extends StatefulWidget {
|
|
String? _selected;
|
|
Dashboard dash;
|
|
final TextEditingController _ctrl = TextEditingController();
|
|
AbstractService<T> service;
|
|
Function validate = () {};
|
|
NewBoxWidget ({ super.key, required this.service, required this.dash, this.getItems });
|
|
@override NewBoxWidgetState<T> createState() => NewBoxWidgetState<T>();
|
|
|
|
List<DropdownMenuItem> Function(APIResponse<T>? data)? getItems;
|
|
}
|
|
class NewBoxWidgetState<T extends SerializerDeserializer<dynamic>> extends State<NewBoxWidget> {
|
|
@override Widget build(BuildContext context) {
|
|
widget._ctrl.value = TextEditingValue(text: widget.dash.defaultName);
|
|
return Container(
|
|
color: Colors.white,
|
|
padding: const EdgeInsets.only( top: 0, bottom: 20, left: 20, right: 20),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
alignment: Alignment.centerRight,
|
|
height: 50,
|
|
child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [
|
|
Padding(padding: const EdgeInsets.symmetric(horizontal: 10), child:
|
|
Text("load or create a new workflow", style: const TextStyle(color: Colors.grey, fontSize: 15)
|
|
)),
|
|
Padding ( padding: const EdgeInsets.symmetric(horizontal: 10), child:
|
|
Tooltip( message: "back", child: InkWell(
|
|
mouseCursor: SystemMouseCursors.click,
|
|
onTap: () {
|
|
AppRouter.catalog.go(context, {});
|
|
},
|
|
child: const Icon(Icons.arrow_back, color: Colors.black))),
|
|
),
|
|
widget.dash.isOpened ? Row ( mainAxisAlignment: MainAxisAlignment.end, children: [
|
|
Tooltip( message: "close", child: InkWell(
|
|
mouseCursor: SystemMouseCursors.click,
|
|
onTap: () { Navigator.pop(context); },
|
|
child: const Icon(Icons.close, color: Colors.black))),
|
|
]) : Container(),
|
|
],),
|
|
),
|
|
FutureBuilder<APIResponse<RawData>>(
|
|
future: (widget.service as AbstractService<T>).all(context),
|
|
builder: (context, snapshot) {
|
|
List<DropdownMenuItem> items = widget.getItems != null ? widget.getItems!(snapshot.data) : [];
|
|
if (widget._selected != null
|
|
&& !items.where((element) => element.value == widget._selected).isNotEmpty) {
|
|
items.add(DropdownMenuItem<String>(
|
|
value: widget._selected.toString(),
|
|
child: Text(widget._selected.toString()),
|
|
));
|
|
}
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children : [
|
|
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: () async {
|
|
if (widget._selected == null || widget._selected!.isEmpty) { return; }
|
|
if (widget._selected != null && widget.dash.load != null) {
|
|
await widget.dash.load!(widget._selected ?? "");
|
|
WorkspaceLocal.init(context, true);
|
|
}
|
|
widget.dash.isOpened = true;
|
|
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) {},
|
|
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, { "name" : widget._ctrl.value.text }, {}).then(
|
|
(value) {
|
|
widget._selected = widget._ctrl.value.text;
|
|
widget._ctrl.value = const TextEditingValue(text: "");
|
|
widget.dash.id = value.data?.serialize()["id"];
|
|
widget.dash.name = widget._selected ?? "";
|
|
widget.dash.notifyListeners();
|
|
WorkspaceLocal.init(context, true);
|
|
widget.dash.isOpened = true;
|
|
// 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)
|
|
)
|
|
)
|
|
)
|
|
])
|
|
]
|
|
)
|
|
);
|
|
}
|
|
} |