Skip to content

Commit

Permalink
After create fail, Create again with the draft
Browse files Browse the repository at this point in the history
  • Loading branch information
HaitaoDeng committed Mar 17, 2022
1 parent d462e4f commit cf13b6b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions lib/ui/util/form_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//

import 'dart:collection';

import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/module/util/csv_utils.dart';
Expand All @@ -32,6 +33,8 @@ class FormUtil {
static const String CANCEL = 'cancel';
static const String CREATE = 'create';

static Map<String, Map<String, String>> lastMap = new HashMap();

static ButtonStyleButton createButton5(String resourceName, List<FormFieldDef> formFieldDefList, BuildContext context,
Function(String, String, String, String, String) callback) {
if (formFieldDefList.length != 5) {
Expand Down Expand Up @@ -76,9 +79,14 @@ class FormUtil {

static ButtonStyleButton createButton(
String resourceName, List<FormFieldDef> formFieldDefList, BuildContext context, Function(List<String>) callback) {
lastMap.putIfAbsent(
resourceName,
() => HashMap.fromIterables(
formFieldDefList.map((e) => e.fieldName).toList(), Iterable.generate(formFieldDefList.length, (i) => "")));
return TextButton(
onPressed: () {
var editControllerList = formFieldDefList.map((e) => TextEditingController()).toList();
var editControllerList =
formFieldDefList.map((e) => TextEditingController(text: lastMap[resourceName]![e.fieldName])).toList();
List<TextFormField> formFieldsList = List.generate(
formFieldDefList.length,
(index) => TextFormField(
Expand All @@ -101,6 +109,8 @@ class FormUtil {
onPressed: () {
var list = editControllerList.map((e) => e.value.text).toList();
callback(list);
lastMap[resourceName] = HashMap.fromIterables(formFieldDefList.map((e) => e.fieldName).toList(),
editControllerList.map((e) => e.value.text));
Navigator.of(context).pop();
},
),
Expand All @@ -127,9 +137,14 @@ class FormUtil {

static ButtonStyleButton createButtonNoText(
String resourceName, List<FormFieldDef> formFieldDefList, BuildContext context, Function(List<String>) callback) {
lastMap.putIfAbsent(
resourceName,
() => HashMap.fromIterables(
formFieldDefList.map((e) => e.fieldName).toList(), Iterable.generate(formFieldDefList.length, (i) => "")));
return TextButton(
onPressed: () {
var editControllerList = formFieldDefList.map((e) => TextEditingController()).toList();
var editControllerList =
formFieldDefList.map((e) => TextEditingController(text: lastMap[resourceName]![e.fieldName])).toList();
List<TextFormField> formFieldsList = List.generate(
formFieldDefList.length,
(index) => TextFormField(
Expand All @@ -152,6 +167,8 @@ class FormUtil {
onPressed: () {
var list = editControllerList.map((e) => e.value.text).toList();
callback(list);
lastMap[resourceName] = HashMap.fromIterables(formFieldDefList.map((e) => e.fieldName).toList(),
editControllerList.map((e) => e.value.text));
Navigator.of(context).pop();
},
),
Expand Down Expand Up @@ -194,9 +211,14 @@ class FormUtil {

static ButtonStyleButton updateButton(
String resourceName, List<FormFieldDef> formFieldDefList, BuildContext context, Function(List<String>) callback) {
lastMap.putIfAbsent(
resourceName,
() => HashMap.fromIterables(
formFieldDefList.map((e) => e.fieldName).toList(), Iterable.generate(formFieldDefList.length, (i) => "")));
return TextButton(
onPressed: () {
var editControllerList = formFieldDefList.map((e) => TextEditingController()).toList();
var editControllerList =
formFieldDefList.map((e) => TextEditingController(text: lastMap[resourceName]![e.fieldName])).toList();
List<TextFormField> formFieldsList = List.generate(
formFieldDefList.length,
(index) => TextFormField(
Expand All @@ -219,6 +241,8 @@ class FormUtil {
onPressed: () {
var list = editControllerList.map((e) => e.value.text).toList();
callback(list);
lastMap[resourceName] = HashMap.fromIterables(formFieldDefList.map((e) => e.fieldName).toList(),
editControllerList.map((e) => e.value.text));
Navigator.of(context).pop();
},
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies:
# window
window_size:
git:
url: git://github.com/google/flutter-desktop-embedding.git
url: https://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size
# paas
http: ^0.13.4
Expand Down

0 comments on commit cf13b6b

Please sign in to comment.