mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
optimize rebuilding of request tables
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:davi/davi.dart';
|
||||
@ -14,17 +15,20 @@ class EditRequestHeaders extends ConsumerStatefulWidget {
|
||||
|
||||
class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
late List<KVRow> rows;
|
||||
final random = Random.secure();
|
||||
late int seed;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
seed = random.nextInt(randRange);
|
||||
}
|
||||
|
||||
Widget _buildHeaderField(BuildContext context, DaviRow<KVRow> row) {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-headers-k"),
|
||||
key: Key("$activeId-$idx-headers-k-$seed"),
|
||||
initialValue: rows[idx].k,
|
||||
style: codeStyle,
|
||||
decoration: InputDecoration(
|
||||
@ -41,7 +45,7 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-headers-v"),
|
||||
key: Key("$activeId-$idx-headers-v-$seed"),
|
||||
initialValue: rows[idx].v,
|
||||
style: codeStyle,
|
||||
decoration: InputDecoration(
|
||||
@ -82,8 +86,13 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
);
|
||||
|
||||
final activeId = ref.watch(activeIdStateProvider);
|
||||
final collection = ref.watch(collectionStateNotifierProvider);
|
||||
/*final collection = ref.watch(collectionStateNotifierProvider);
|
||||
final idIdx = collection.indexWhere((m) => m.id == activeId);
|
||||
rows = collection[idIdx].requestHeaders ?? [const KVRow("", "")];*/
|
||||
final collection = ref.read(collectionStateNotifierProvider);
|
||||
final idIdx = collection.indexWhere((m) => m.id == activeId);
|
||||
final length = ref.watch(collectionStateNotifierProvider
|
||||
.select((value) => value[idIdx].requestHeaders?.length));
|
||||
rows = collection[idIdx].requestHeaders ?? [const KVRow("", "")];
|
||||
DaviModel<KVRow> model = DaviModel<KVRow>(
|
||||
rows: rows,
|
||||
@ -112,6 +121,7 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
),
|
||||
onTap: () {
|
||||
rows.removeAt(row.index);
|
||||
seed = random.nextInt(randRange);
|
||||
_onFieldChange(activeId!);
|
||||
},
|
||||
);
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:davi/davi.dart';
|
||||
@ -15,17 +16,20 @@ class EditRequestURLParams extends ConsumerStatefulWidget {
|
||||
|
||||
class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
late List<KVRow> rows;
|
||||
final random = Random.secure();
|
||||
late int seed;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
seed = random.nextInt(randRange);
|
||||
}
|
||||
|
||||
Widget _buildParamField(BuildContext context, DaviRow<KVRow> row) {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-params-k"),
|
||||
key: Key("$activeId-$idx-params-k-$seed"),
|
||||
initialValue: rows[idx].k,
|
||||
style: codeStyle,
|
||||
decoration: InputDecoration(
|
||||
@ -42,7 +46,7 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-params-v"),
|
||||
key: Key("$activeId-$idx-params-v-$seed"),
|
||||
initialValue: rows[idx].v,
|
||||
style: codeStyle,
|
||||
decoration: InputDecoration(
|
||||
@ -83,8 +87,10 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
);
|
||||
|
||||
final activeId = ref.watch(activeIdStateProvider);
|
||||
final collection = ref.watch(collectionStateNotifierProvider);
|
||||
final collection = ref.read(collectionStateNotifierProvider);
|
||||
final idIdx = collection.indexWhere((m) => m.id == activeId);
|
||||
final length = ref.watch(collectionStateNotifierProvider
|
||||
.select((value) => value[idIdx].requestParams?.length));
|
||||
rows = collection[idIdx].requestParams ?? [const KVRow("", "")];
|
||||
DaviModel<KVRow> model = DaviModel<KVRow>(
|
||||
rows: rows,
|
||||
@ -113,6 +119,7 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
),
|
||||
onTap: () {
|
||||
rows.removeAt(row.index);
|
||||
seed = random.nextInt(randRange);
|
||||
_onFieldChange(activeId!);
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user