mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 05:32:26 +08:00
Add Table CellField
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:davi/davi.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
@ -24,76 +25,6 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
seed = random.nextInt(kRandMax);
|
||||
}
|
||||
|
||||
Widget _buildHeaderField(BuildContext context, DaviRow<KVRow> row) {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-headers-k-$seed"),
|
||||
initialValue: rows[idx].k,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.outline.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
hintText: "Add Header Name",
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(k: value);
|
||||
_onFieldChange(activeId!);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildValueField(BuildContext context, DaviRow<KVRow> row) {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-headers-v-$seed"),
|
||||
initialValue: rows[idx].v,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.outline.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
hintText: " Add Header Value",
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(v: value);
|
||||
_onFieldChange(activeId!);
|
||||
});
|
||||
}
|
||||
|
||||
void _onFieldChange(String activeId) {
|
||||
ref
|
||||
.read(collectionStateNotifierProvider.notifier)
|
||||
@ -103,18 +34,29 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final activeId = ref.watch(activeIdStateProvider);
|
||||
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("", "")];
|
||||
final length = ref.watch(activeRequestModelProvider
|
||||
.select((value) => value?.requestHeaders?.length));
|
||||
rows = ref.read(activeRequestModelProvider)?.requestHeaders ??
|
||||
[const KVRow("", "")];
|
||||
DaviModel<KVRow> model = DaviModel<KVRow>(
|
||||
rows: rows,
|
||||
columns: [
|
||||
DaviColumn(
|
||||
name: 'Header Name',
|
||||
grow: 1,
|
||||
cellBuilder: (_, row) => _buildHeaderField(context, row),
|
||||
cellBuilder: (_, row) {
|
||||
int idx = row.index;
|
||||
return CellField(
|
||||
colorScheme: Theme.of(context).colorScheme,
|
||||
keyId: "$activeId-$idx-headers-k-$seed",
|
||||
initialValue: rows[idx].k,
|
||||
hintText: "Add Header Name",
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(k: value);
|
||||
_onFieldChange(activeId!);
|
||||
},
|
||||
);
|
||||
},
|
||||
sortable: false,
|
||||
),
|
||||
DaviColumn(
|
||||
@ -129,7 +71,19 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
||||
DaviColumn(
|
||||
name: 'Header Value',
|
||||
grow: 1,
|
||||
cellBuilder: (_, row) => _buildValueField(context, row),
|
||||
cellBuilder: (_, row) {
|
||||
int idx = row.index;
|
||||
return CellField(
|
||||
colorScheme: Theme.of(context).colorScheme,
|
||||
keyId: "$activeId-$idx-headers-v-$seed",
|
||||
initialValue: rows[idx].v,
|
||||
hintText: " Add Header Value",
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(v: value);
|
||||
_onFieldChange(activeId!);
|
||||
},
|
||||
);
|
||||
},
|
||||
sortable: false,
|
||||
),
|
||||
DaviColumn(
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:davi/davi.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
@ -25,76 +26,6 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
seed = random.nextInt(kRandMax);
|
||||
}
|
||||
|
||||
Widget _buildParamField(BuildContext context, DaviRow<KVRow> row) {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-params-k-$seed"),
|
||||
initialValue: rows[idx].k,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.outline.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
hintText: "Add URL Parameter",
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(k: value);
|
||||
_onFieldChange(activeId!);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildValueField(BuildContext context, DaviRow<KVRow> row) {
|
||||
String? activeId = ref.read(activeIdStateProvider);
|
||||
int idx = row.index;
|
||||
return TextFormField(
|
||||
key: Key("$activeId-$idx-params-v-$seed"),
|
||||
initialValue: rows[idx].v,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.outline.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
hintText: "Add Value",
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(v: value);
|
||||
_onFieldChange(activeId!);
|
||||
});
|
||||
}
|
||||
|
||||
void _onFieldChange(String activeId) {
|
||||
ref
|
||||
.read(collectionStateNotifierProvider.notifier)
|
||||
@ -104,11 +35,10 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final activeId = ref.watch(activeIdStateProvider);
|
||||
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("", "")];
|
||||
final length = ref.watch(activeRequestModelProvider
|
||||
.select((value) => value?.requestParams?.length));
|
||||
rows = ref.read(activeRequestModelProvider)?.requestParams ??
|
||||
[const KVRow("", "")];
|
||||
|
||||
DaviModel<KVRow> model = DaviModel<KVRow>(
|
||||
rows: rows,
|
||||
@ -116,7 +46,19 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
DaviColumn(
|
||||
name: 'URL Parameter',
|
||||
grow: 1,
|
||||
cellBuilder: (_, row) => _buildParamField(context, row),
|
||||
cellBuilder: (_, row) {
|
||||
int idx = row.index;
|
||||
return CellField(
|
||||
colorScheme: Theme.of(context).colorScheme,
|
||||
keyId: "$activeId-$idx-params-k-$seed",
|
||||
initialValue: rows[idx].k,
|
||||
hintText: "Add URL Parameter",
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(k: value);
|
||||
_onFieldChange(activeId!);
|
||||
},
|
||||
);
|
||||
},
|
||||
sortable: false,
|
||||
),
|
||||
DaviColumn(
|
||||
@ -131,7 +73,19 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
|
||||
DaviColumn(
|
||||
name: 'Value',
|
||||
grow: 1,
|
||||
cellBuilder: (_, row) => _buildValueField(context, row),
|
||||
cellBuilder: (_, row) {
|
||||
int idx = row.index;
|
||||
return CellField(
|
||||
colorScheme: Theme.of(context).colorScheme,
|
||||
keyId: "$activeId-$idx-params-v-$seed",
|
||||
initialValue: rows[idx].v,
|
||||
hintText: "Add Value",
|
||||
onChanged: (value) {
|
||||
rows[idx] = rows[idx].copyWith(v: value);
|
||||
_onFieldChange(activeId!);
|
||||
},
|
||||
);
|
||||
},
|
||||
sortable: false,
|
||||
),
|
||||
DaviColumn(
|
||||
|
@ -42,3 +42,56 @@ class _URLFieldState extends State<URLField> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CellField extends StatefulWidget {
|
||||
const CellField(
|
||||
{super.key,
|
||||
required this.colorScheme,
|
||||
required this.keyId,
|
||||
required this.initialValue,
|
||||
this.hintText,
|
||||
this.onChanged});
|
||||
|
||||
final ColorScheme colorScheme;
|
||||
final String keyId;
|
||||
final String initialValue;
|
||||
final String? hintText;
|
||||
final void Function(String)? onChanged;
|
||||
|
||||
@override
|
||||
State<CellField> createState() => _CellFieldState();
|
||||
}
|
||||
|
||||
class _CellFieldState extends State<CellField> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
key: Key(widget.keyId),
|
||||
initialValue: widget.initialValue,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: widget.colorScheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: kCodeStyle.copyWith(
|
||||
color: widget.colorScheme.outline.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
hintText: widget.hintText,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: widget.colorScheme.primary.withOpacity(
|
||||
kHintOpacity,
|
||||
),
|
||||
),
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: widget.colorScheme.surfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: widget.onChanged,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user