Skip to content

Commit

Permalink
make workable args and kwargs in register action
Browse files Browse the repository at this point in the history
  • Loading branch information
shakeebkhan66 committed Jun 4, 2024
1 parent f86eea8 commit 2857da8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
8 changes: 4 additions & 4 deletions lib/providers/kwargs_provider.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import "package:flutter/cupertino.dart";

class KwargsProvider extends ChangeNotifier {
final List<Map<String, dynamic>> _tableData = [
{"key": "", "value": ""},
final List<MapEntry<String, dynamic>> _tableData = [
const MapEntry("", ""),
];

List<Map<String, dynamic>> get tableData => _tableData;
List<MapEntry<String, dynamic>> get tableData => _tableData;

void addRow(Map<String, String> rowData) {
void addRow(MapEntry<String, String> rowData) {
_tableData.add(rowData);
notifyListeners();
}
Expand Down
18 changes: 6 additions & 12 deletions lib/screens/mobile/mobile_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,8 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
Future<void> _publish(int index) async {
List<String> argsData = _argsProviders[index].controllers.map((controller) => controller.text).toList();
Map<String, dynamic> kWarValues = {};
for (final map in _kwargsProviders[index].tableData) {
String key = map["key"];
dynamic value = map["value"];
kWarValues[key] = value;
for (final mapEntry in _kwargsProviders[index].tableData) {
kWarValues[mapEntry.key] = mapEntry.value;
}

try {
Expand Down Expand Up @@ -755,10 +753,8 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
var sessionProvider = Provider.of<SessionStateProvider>(context, listen: false);
List<String> argsData = _argsProviders[index].controllers.map((controller) => controller.text).toList();
Map<String, dynamic> kWarValues = {};
for (final map in _kwargsProviders[index].tableData) {
String key = map["key"];
dynamic value = map["value"];
kWarValues[key] = value;
for (final mapEntry in _kwargsProviders[index].tableData) {
kWarValues[mapEntry.key] = mapEntry.value;
}

try {
Expand Down Expand Up @@ -829,10 +825,8 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
try {
List<String> argsData = _argsProviders[index].controllers.map((controller) => controller.text).toList();
Map<String, dynamic> kWarValues = {};
for (final map in _kwargsProviders[index].tableData) {
String key = map["key"];
dynamic value = map["value"];
kWarValues[key] = value;
for (final mapEntry in _kwargsProviders[index].tableData) {
kWarValues[mapEntry.key] = mapEntry.value;
}
var session = await connect(
_tabData[index].linkController.text,
Expand Down
43 changes: 27 additions & 16 deletions lib/utils/kwargs_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class _DynamicKeyValuePairsState extends State<DynamicKeyValuePairs> {
return Consumer<KwargsProvider>(
builder: (context, tableProvider, _) {
Map<String, dynamic> kWarValues = {};
for (final map in tableProvider.tableData) {
String key = map["key"];
dynamic value = map["value"];
if (key.isNotEmpty) {
kWarValues[key] = value;
for (final mapEntry in tableProvider.tableData) {
// String key = map["key"];
// dynamic value = map["value"];
if (mapEntry.key.isNotEmpty) {
kWarValues[mapEntry.key] = mapEntry.value;
}
}

Expand Down Expand Up @@ -61,10 +61,13 @@ class _DynamicKeyValuePairsState extends State<DynamicKeyValuePairs> {
IconButton(
onPressed: () {
setState(() {
widget.provider.addRow({
"key": "",
"value": "",
});
widget.provider.addRow(const MapEntry("", ""));
// widget.provider.addRow(
// {
// "key": "",
// "value": "",
// }
// );
});
},
icon: const Icon(
Expand Down Expand Up @@ -94,7 +97,7 @@ class _DynamicKeyValuePairsState extends State<DynamicKeyValuePairs> {
class TableWidget extends StatefulWidget {
const TableWidget(this.tableData, this.provider, {super.key});

final List<Map<String, dynamic>> tableData;
final List<MapEntry<String, dynamic>> tableData;
final KwargsProvider provider;

@override
Expand All @@ -104,23 +107,27 @@ class TableWidget extends StatefulWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(IterableProperty<Map<String, dynamic>>("tableData", tableData))
..add(IterableProperty<MapEntry<String, dynamic>>("tableData", tableData))
..add(DiagnosticsProperty<KwargsProvider>("provider", provider));
}
}

class _TableWidgetState extends State<TableWidget> {
TableRow _buildTableRow(
Map<String, dynamic> rowData,
MapEntry<String, dynamic> rowData,
int index,
) {
return TableRow(
children: [
_buildTableCell(
TextFormField(
initialValue: rowData["key"],
initialValue: rowData.key,
onChanged: (newValue) {
rowData["key"] = newValue;
setState(() {
final index = widget.tableData.indexOf(rowData);
final updatedEntry = MapEntry<String, dynamic>(newValue, rowData.value);
widget.tableData[index] = updatedEntry;
});
},
decoration: const InputDecoration(
border: InputBorder.none,
Expand All @@ -130,9 +137,13 @@ class _TableWidgetState extends State<TableWidget> {
),
_buildTableCell(
TextFormField(
initialValue: rowData["value"],
initialValue: rowData.value.toString(),
onChanged: (newValue) {
rowData["value"] = newValue;
setState(() {
final index = widget.tableData.indexOf(rowData);
final updatedEntry = MapEntry<String, dynamic>(rowData.key, newValue);
widget.tableData[index] = updatedEntry;
});
},
decoration: const InputDecoration(
border: InputBorder.none,
Expand Down

0 comments on commit 2857da8

Please sign in to comment.