Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save previous field data & refactor UI #52

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/providers/kwargs_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import "package:flutter/cupertino.dart";

class KwargsProvider extends ChangeNotifier {
final List<MapEntry<String, String>> _tableData = [
const MapEntry("", ""),
];
final List<MapEntry<String, String>> _tableData = [];

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

Expand Down
48 changes: 19 additions & 29 deletions lib/screens/mobile/mobile_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,21 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
const SizedBox(height: 20),
buildArgs(_tabData[index].sendButtonText, _argsProviders[index]),
const SizedBox(height: 20),
const Divider(),
buildKwargs(_tabData[index].sendButtonText, _kwargsProviders[index]),
const SizedBox(height: 50),
resultText(_tabData[index].sendButtonText),
const Divider(),
Consumer3<InvocationProvider, EventProvider, ResultProvider>(
builder: (context, invocationProvider, eventProvider, resultProvider, child) {
final hasInvocationResults = _hasResults(index, invocationProvider.invocations);
final hasEventsResults = _hasResults(index, eventProvider.events);
final hasCallResults = _hasResults(index, resultProvider.results);
if (hasInvocationResults || hasEventsResults || hasCallResults) {
return resultText(_tabData[index].sendButtonText);
} else {
return Container();
}
},
),
_buildInvocationResults(index),
_buildEventResults(index),
_buildCallResults(index),
Expand All @@ -356,6 +368,10 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
);
}

bool _hasResults(int index, List<String> results) {
return results.where((result) => result.startsWith("$index:")).isNotEmpty;
}

Widget _buildTabActionDropdown(int index) {
return Padding(
padding: const EdgeInsets.only(left: 15, right: 15, top: 5),
Expand Down Expand Up @@ -580,14 +596,7 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
args: argsData,
kwargs: kWarValues,
);
setState(() {
_tabData[index].linkController.clear();
_tabData[index].realmController.clear();
_tabData[index].topicProcedureController.clear();
_argsProviders[index].controllers.clear();
_kwargsProviders[index].tableData.clear();
_tabData[index].selectedSerializer = "";
});
setState(() {});
} on Exception catch (e) {
return Future.error(e);
}
Expand Down Expand Up @@ -756,9 +765,6 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
await session?.unregister(reg);
setState(() {
_tabData[index].sendButtonText = "Register";
_tabData[index].selectedSerializer = "";
_tabData[index].selectedValue = "";
_tabData[index].topicProcedureController.clear();
Provider.of<InvocationProvider>(context, listen: false).invocations.clear();
});
}
Expand All @@ -767,8 +773,6 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
await session?.unsubscribe(sub);
setState(() {
_tabData[index].sendButtonText = "Subscribe";
_tabData[index].selectedSerializer = "";
_tabData[index].selectedValue = "";
Provider.of<EventProvider>(context, listen: false).events.clear();
});
}
Expand Down Expand Up @@ -803,11 +807,6 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
setState(() {
var unregister = _tabData[index].sendButtonText = "UnRegister";
sendButton(unregister, index);
_tabData[index].linkController.clear();
_tabData[index].realmController.clear();
_tabData[index].selectedSerializer = "";
_argsProviders[index].controllers.clear();
_kwargsProviders[index].tableData.clear();
});
} on Exception catch (error) {
throw Exception(error);
Expand Down Expand Up @@ -835,9 +834,6 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
setState(() {
var unsubscribe = _tabData[index].sendButtonText = "UnSubscribe";
sendButton(unsubscribe, index);
_tabData[index].linkController.clear();
_tabData[index].realmController.clear();
_tabData[index].selectedSerializer = "";
});
} on Exception catch (error) {
throw Exception(error);
Expand Down Expand Up @@ -867,12 +863,6 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
resultProvider.results.clear();
String result = "$index: args=${calls.args}, kwargs=${calls.kwargs}";
resultProvider.addResult(result);

_tabData[index].linkController.clear();
_tabData[index].realmController.clear();
_tabData[index].selectedSerializer = "";
_argsProviders[index].controllers.clear();
_kwargsProviders[index].tableData.clear();
} on Exception catch (error) {
throw Exception(error);
}
Expand Down
76 changes: 39 additions & 37 deletions lib/utils/kwargs_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,45 @@ class _TableWidgetState extends State<TableWidget> {

@override
Widget build(BuildContext context) {
return Table(
border: TableBorder.all(color: Colors.grey),
columnWidths: const {
0: FixedColumnWidth(150),
1: FixedColumnWidth(150),
2: FixedColumnWidth(50),
},
children: [
TableRow(
children: [
_buildTableCell(
const Text(
"Key",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
_buildTableCell(
const Text(
"Value",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
_buildTableCell(
const Text(
"",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
],
),
...widget.tableData.asMap().entries.map(
(entry) => _buildTableRow(
entry.value,
entry.key,
return widget.tableData.isNotEmpty
? Table(
border: TableBorder.all(color: Colors.grey),
columnWidths: const {
0: FixedColumnWidth(150),
1: FixedColumnWidth(150),
2: FixedColumnWidth(50),
},
children: [
TableRow(
children: [
_buildTableCell(
const Text(
"Key",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
_buildTableCell(
const Text(
"Value",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
_buildTableCell(
const Text(
"",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
],
),
),
],
);
...widget.tableData.asMap().entries.map(
(entry) => _buildTableRow(
entry.value,
entry.key,
),
),
],
)
: Container();
}
}
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.6
dynamic_tabbar: ^1.0.7

flutter:
sdk: flutter
fluttertoast: ^8.2.5
provider: ^6.1.2
shared_preferences: ^2.2.3
tabbed_view: ^1.18.0
xconn:
git: https://github.com/xconnio/xconn-dart

Expand Down