oc-front/lib/widgets/dialog/shallow_creation.dart

96 lines
4.5 KiB
Dart
Raw Permalink Normal View History

2024-08-30 12:52:32 +02:00
import 'package:flutter/material.dart';
import 'package:oc_front/models/response.dart';
import 'package:oc_front/core/services/router.dart';
import 'package:oc_front/pages/shared.dart';
import 'package:oc_front/widgets/inputs/shallow_dropdown_input.dart';
import 'package:oc_front/widgets/inputs/shallow_text_input.dart';
class ShallowCreationDialogWidget extends StatefulWidget {
GlobalKey<ShallowTextInputWidgetState>? formKey;
BuildContext context;
bool Function()? canClose;
SharedWorkspaceType type = SharedWorkspaceType.workspace;
Future<List<Shallow>> Function()? all;
Future<void> Function(String)? load;
Future<void> Function(Map<String,dynamic>)? create;
bool Function(String?)? canLoad;
DropdownMenuItem Function(Shallow)? maptoDropdown;
List<ShallowTextInputWidget> form = [];
ShallowCreationDialogWidget ({ super.key, required this.type, required this.all, this.load, this.formKey,
required this.create, this.form = const [], this.maptoDropdown, required this.context, this.canClose }) ;
@override ShallowCreationDialogState createState() => ShallowCreationDialogState();
}
class ShallowCreationDialogState extends State<ShallowCreationDialogWidget> {
GlobalKey<FormFieldState> key = GlobalKey<FormFieldState>();
GlobalKey<FormFieldState> key2 = GlobalKey<FormFieldState>();
@override Widget build(BuildContext context) {
var t = widget.type == SharedWorkspaceType.workspace ? "workspace" : (widget.type == SharedWorkspaceType.workflow ? "workflow" : (widget.type == SharedWorkspaceType.shared_workspace ? "shared workspace" :"peer"));
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 $t", 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.canClose != null && !widget.canClose!() ? Container() : 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))),
]),
],),
),
ShallowDropdownInputWidget(
all: widget.all,
type: widget.type,
width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 140 : 400,
load: (e) async {
await widget.load!(e);
Navigator.pop(widget.context);
},
iconLoad: Icons.open_in_browser_outlined,
iconRemove: Icons.refresh,
maptoDropdown: widget.maptoDropdown,
canLoad: (p0) => p0 != null && p0.isNotEmpty,
canRemove: (p0) => p0 != null && p0.isNotEmpty,
tooltipRemove: "refresh selection",
deletion: true,
color: Colors.black,
hintColor: Colors.grey,
filled: Colors.grey.shade300,
),
Container( height: 10),
ShallowTextInputWidget(
key: widget.formKey,
type: widget.type,
width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 140 : 400,
load: (e) async {
await widget.create!(e);
Navigator.pop(widget.context);
},
forms: widget.form,
canLoad: (p0) => p0 != null && p0.isNotEmpty,
color: Colors.black,
hintColor: Colors.grey,
filled: Colors.grey.shade300,
),
...widget.form.map( (e) => Container( margin: const EdgeInsets.only(top: 10), child: e)),
]
)
);
}
}