diff --git a/lib/providers/kwargs_provider.dart b/lib/providers/kwargs_provider.dart index bf2683c..9eb7ab5 100644 --- a/lib/providers/kwargs_provider.dart +++ b/lib/providers/kwargs_provider.dart @@ -1,13 +1,13 @@ import "package:flutter/cupertino.dart"; class KwargsProvider extends ChangeNotifier { - final List> _tableData = [ - {"key": "", "value": ""}, + final List> _tableData = [ + const MapEntry("", ""), ]; - List> get tableData => _tableData; + List> get tableData => _tableData; - void addRow(Map rowData) { + void addRow(MapEntry rowData) { _tableData.add(rowData); notifyListeners(); } diff --git a/lib/screens/mobile/mobile_home.dart b/lib/screens/mobile/mobile_home.dart index 730c411..e1075f5 100644 --- a/lib/screens/mobile/mobile_home.dart +++ b/lib/screens/mobile/mobile_home.dart @@ -543,10 +543,8 @@ class _MobileHomeScaffoldState extends State with TickerProv Future _publish(int index) async { List argsData = _argsProviders[index].controllers.map((controller) => controller.text).toList(); Map 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 { @@ -755,10 +753,8 @@ class _MobileHomeScaffoldState extends State with TickerProv var sessionProvider = Provider.of(context, listen: false); List argsData = _argsProviders[index].controllers.map((controller) => controller.text).toList(); Map 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 { @@ -829,10 +825,8 @@ class _MobileHomeScaffoldState extends State with TickerProv try { List argsData = _argsProviders[index].controllers.map((controller) => controller.text).toList(); Map 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, diff --git a/lib/utils/kwargs_screen.dart b/lib/utils/kwargs_screen.dart index 59f04cc..e85dd8a 100644 --- a/lib/utils/kwargs_screen.dart +++ b/lib/utils/kwargs_screen.dart @@ -24,11 +24,11 @@ class _DynamicKeyValuePairsState extends State { return Consumer( builder: (context, tableProvider, _) { Map 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; } } @@ -61,10 +61,13 @@ class _DynamicKeyValuePairsState extends State { IconButton( onPressed: () { setState(() { - widget.provider.addRow({ - "key": "", - "value": "", - }); + widget.provider.addRow(const MapEntry("", "")); + // widget.provider.addRow( + // { + // "key": "", + // "value": "", + // } + // ); }); }, icon: const Icon( @@ -94,7 +97,7 @@ class _DynamicKeyValuePairsState extends State { class TableWidget extends StatefulWidget { const TableWidget(this.tableData, this.provider, {super.key}); - final List> tableData; + final List> tableData; final KwargsProvider provider; @override @@ -104,23 +107,27 @@ class TableWidget extends StatefulWidget { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(IterableProperty>("tableData", tableData)) + ..add(IterableProperty>("tableData", tableData)) ..add(DiagnosticsProperty("provider", provider)); } } class _TableWidgetState extends State { TableRow _buildTableRow( - Map rowData, + MapEntry 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(newValue, rowData.value); + widget.tableData[index] = updatedEntry; + }); }, decoration: const InputDecoration( border: InputBorder.none, @@ -130,9 +137,13 @@ class _TableWidgetState extends State { ), _buildTableCell( TextFormField( - initialValue: rowData["value"], + initialValue: rowData.value.toString(), onChanged: (newValue) { - rowData["value"] = newValue; + setState(() { + final index = widget.tableData.indexOf(rowData); + final updatedEntry = MapEntry(rowData.key, newValue); + widget.tableData[index] = updatedEntry; + }); }, decoration: const InputDecoration( border: InputBorder.none,