Skip to content

Commit

Permalink
removed unneeded callback between controller and UI...
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanofornari committed Jun 4, 2022
1 parent 85559c0 commit f791244
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_ios-2.1.0/","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_android-2.0.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.3/","native_build":true,"dependencies":[]},{"name":"window_size","path":"/usr/lib/flutter/.pub-cache/git/flutter-desktop-embedding-89c350f787e1d7bff12b3517e5671146211ee70e/plugins/window_size/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.5/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.1.0/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"window_size","path":"/usr/lib/flutter/.pub-cache/git/flutter-desktop-embedding-89c350f787e1d7bff12b3517e5671146211ee70e/plugins/window_size/","native_build":true,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.5/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.1.0/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"window_size","path":"/usr/lib/flutter/.pub-cache/git/flutter-desktop-embedding-89c350f787e1d7bff12b3517e5671146211ee70e/plugins/window_size/","native_build":true,"dependencies":[]}],"web":[{"name":"shared_preferences_web","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.3/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"window_size","dependencies":[]}],"date_created":"2022-06-04 12:40:59.301745","version":"3.1.0-0.0.pre.1101"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_ios-2.1.0/","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_android-2.0.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.3/","native_build":true,"dependencies":[]},{"name":"window_size","path":"/usr/lib/flutter/.pub-cache/git/flutter-desktop-embedding-89c350f787e1d7bff12b3517e5671146211ee70e/plugins/window_size/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.5/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.1.0/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"window_size","path":"/usr/lib/flutter/.pub-cache/git/flutter-desktop-embedding-89c350f787e1d7bff12b3517e5671146211ee70e/plugins/window_size/","native_build":true,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.5/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.1.0/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"window_size","path":"/usr/lib/flutter/.pub-cache/git/flutter-desktop-embedding-89c350f787e1d7bff12b3517e5671146211ee70e/plugins/window_size/","native_build":true,"dependencies":[]}],"web":[{"name":"shared_preferences_web","path":"/usr/lib/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.3/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"window_size","dependencies":[]}],"date_created":"2022-06-04 17:36:04.435418","version":"3.1.0-0.0.pre.1101"}
16 changes: 5 additions & 11 deletions lib/ui/wallet_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,10 @@ class EasyWalletHomePage extends StatefulWidget {
class _EasyWalletState extends State<EasyWalletHomePage> {
final WalletListController controller = WalletListController();

void _onChange() async {
setState(() {});
//
// TODO: to be isolated in a Application controller...
//
ew.preferences.wallets = controller.value;
ew.savePreferences();
}

@override
void initState() {
super.initState();
controller.value = ew.preferences.wallets;
controller.addListener(_onChange);
}

@override
Expand Down Expand Up @@ -102,6 +92,7 @@ class _EasyWalletState extends State<EasyWalletHomePage> {
if (address.isNotEmpty) {
controller + EasyWallet(address);
}
setState(() {});
},
),
);
Expand Down Expand Up @@ -135,7 +126,10 @@ class _EasyWalletState extends State<EasyWalletHomePage> {

for (var wallet in controller.value) {
cards.add(
WalletCard(wallet, () {controller - wallet.address;})
WalletCard(wallet, () {
controller - wallet.address;
setState(() {});
})
);
}

Expand Down
10 changes: 8 additions & 2 deletions lib/ui/wallet_list_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class WalletListController extends ValueNotifier<List<EasyWallet>> {
WalletListController operator +(EasyWallet wallet) {
value.add(wallet);
walletManager.balance(wallet).whenComplete(() => notifyListeners());
notifyListeners();

_savePreferences();

return this;
}

Expand All @@ -30,7 +31,7 @@ class WalletListController extends ValueNotifier<List<EasyWallet>> {
});

if (value.length != l) {
notifyListeners();
_savePreferences();
}

return this;
Expand All @@ -47,4 +48,9 @@ class WalletListController extends ValueNotifier<List<EasyWallet>> {
return element.address == address;
});
}

_savePreferences() {
ew.preferences.wallets = value;
ew.savePreferences();
}
}
2 changes: 1 addition & 1 deletion test/ui/edit_private_key_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
EasyWallet wallet = EasyWallet(ADDRESS3.substring(2));

home.state.controller + wallet;
await tester.pumpAndSettle();
tester.state(find.byType(EasyWalletHomePage)).setState(() {}); await tester.pump();

var button = find.descendant(of: find.byKey(Key(ADDRESS3.substring(2))), matching: find.byIcon(Icons.lock_open));

Expand Down
8 changes: 7 additions & 1 deletion test/ui/wallet_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,24 @@ void main() {
testWidgets('adding/removing a wallet updates the cards view', (WidgetTester tester) async {
EasyWalletHomePage home = await givenWlalletManagerStub(tester);

var homeFinder = find.byType(EasyWalletHomePage);

home.state.controller + EasyWallet(WALLET1);
tester.state(homeFinder).setState(() {});
await tester.pumpAndSettle();
expect(find.byType(Card), findsOneWidget);
expect(find.byKey(Key(WALLET1)), findsOneWidget);
expect(findTextInCard(tester, Key(WALLET1), WALLET1), true);

home.state.controller + EasyWallet(WALLET2);
tester.state(homeFinder).setState(() {});
await tester.pump();
expect(find.byType(Card), findsNWidgets(2));
expect(find.byKey(Key(WALLET2)), findsOneWidget);
expect(findTextInCard(tester, Key(WALLET2), WALLET2), true);

home.state.controller - WALLET2;
tester.state(homeFinder).setState(() {});
await tester.pump();
expect(find.byType(Card), findsOneWidget);
expect(find.byKey(Key(WALLET1)), findsOneWidget);
Expand All @@ -76,6 +81,7 @@ void main() {
// add a couple of wallets
//
home.state.controller + EasyWallet(WALLET1) + EasyWallet(WALLET2);
tester.state(find.byType(EasyWalletHomePage)).setState(() {}); await tester.pump();

//
// trigger refresh
Expand Down Expand Up @@ -113,8 +119,8 @@ void main() {
EasyWalletHomePage home = await givenWlalletManagerStub(tester);

home.state.controller + EasyWallet(WALLET1);
tester.state(find.byType(EasyWalletHomePage)).setState(() {}); await tester.pump();

await tester.pumpAndSettle();
expect(find.descendant(of: find.byKey(Key(WALLET1)), matching: find.text("\n 18.424220187167293", findRichText: true)), findsOneWidget);
});

Expand Down
6 changes: 3 additions & 3 deletions test/ui/wallet_card_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
EasyWalletHomePage home = await givenWlalletManagerStub(tester);

home.state.controller + EasyWallet(WALLET1);
await tester.pumpAndSettle();
tester.state(find.byType(EasyWalletHomePage)).setState(() {}); await tester.pump();

var card = find.byKey(Key(WALLET1));
expect(
Expand All @@ -43,7 +43,7 @@ void main() {
EasyWalletHomePage home = await givenWlalletManagerStub(tester);

home.state.controller + EasyWallet(WALLET1);
await tester.pumpAndSettle();
tester.state(find.byType(EasyWalletHomePage)).setState(() {}); await tester.pump();

var button = find.descendant(of: find.byKey(Key(WALLET1)), matching: find.byIcon(Icons.delete));

Expand All @@ -57,7 +57,7 @@ void main() {
EasyWalletHomePage home = await givenWlalletManagerStub(tester);

home.state.controller + EasyWallet(WALLET1);
await tester.pumpAndSettle();
tester.state(find.byType(EasyWalletHomePage)).setState(() {}); await tester.pump();

var button = find.descendant(of: find.byKey(Key(WALLET1)), matching: find.byIcon(Icons.lock_open));

Expand Down
23 changes: 0 additions & 23 deletions test/ui/wallet_list_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void main() {

ew.preferences.endpoint = "https://a.endpoint.io/v3";
ew.preferences.appkey = "PROJECTKEY1";
KEY_CFG_APPKEY:
configFile.writeAsStringSync(json.encoder.convert(ew.preferences));

wm = WalletManageWithStub("https://a.endpoint.io/v3/PROJECTKEY1");
Expand Down Expand Up @@ -85,28 +84,6 @@ void main() {

});

test('call back the listeners upon changes', () {
bool fired = false;

C.addListener(() { fired = true; });

//
// do not fire if empty
//
C - W1;
expect(fired, false);

C + EasyWallet(W1);
expect(fired, true);

fired = false; C - W1;
expect(fired, true);

C + EasyWallet(W1); fired = false;
C - W2; // not in the list, do not fire a change
expect(fired, false);
});

test('valid address is not in the list', () {
WalletListController C = WalletListController();

Expand Down

0 comments on commit f791244

Please sign in to comment.