-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use flutter redux for state management.
- Loading branch information
Showing
20 changed files
with
232 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class BtoxUpdateNicknameAction { | ||
final String nickname; | ||
|
||
const BtoxUpdateNicknameAction(this.nickname); | ||
} | ||
|
||
class BtoxUpdateStatusMessageAction { | ||
final String statusMessage; | ||
|
||
const BtoxUpdateStatusMessageAction(this.statusMessage); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:btox/btox_state.dart'; | ||
import 'package:btox/contact_list_page.dart'; | ||
import 'package:btox/db/database.dart'; | ||
import 'package:btox/strings.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_redux/flutter_redux.dart'; | ||
import 'package:redux/redux.dart'; | ||
|
||
final class BtoxApp extends StatelessWidget { | ||
final Database database; | ||
final Store<BtoxState> store; | ||
|
||
const BtoxApp({ | ||
super.key, | ||
required this.database, | ||
required this.store, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return StoreProvider<BtoxState>( | ||
store: store, | ||
child: MaterialApp( | ||
title: Strings.title, | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
home: ContactListPage(title: Strings.title, database: database), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:btox/btox_state.dart'; | ||
import 'package:btox/btox_actions.dart'; | ||
import 'package:redux/redux.dart'; | ||
|
||
final btoxReducer = combineReducers<BtoxState>([ | ||
TypedReducer<BtoxState, BtoxUpdateNicknameAction>(_updateNickname).call, | ||
TypedReducer<BtoxState, BtoxUpdateStatusMessageAction>(_updateStatusMessage) | ||
.call, | ||
]); | ||
|
||
BtoxState _updateNickname(BtoxState state, BtoxUpdateNicknameAction action) { | ||
return state.copyWith(nickname: action.nickname); | ||
} | ||
|
||
BtoxState _updateStatusMessage( | ||
BtoxState state, BtoxUpdateStatusMessageAction action) { | ||
return state.copyWith(statusMessage: action.statusMessage); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
final class BtoxState { | ||
final String nickname; | ||
final String statusMessage; | ||
|
||
const BtoxState({ | ||
required this.nickname, | ||
required this.statusMessage, | ||
}); | ||
|
||
const BtoxState.initial() | ||
: nickname = 'Yanciman', | ||
statusMessage = 'Producing works of art in Kannywood'; | ||
|
||
BtoxState copyWith({ | ||
String? nickname, | ||
String? statusMessage, | ||
}) { | ||
return BtoxState( | ||
nickname: nickname ?? this.nickname, | ||
statusMessage: statusMessage ?? this.statusMessage, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import 'database.dart'; | ||
import 'package:btox/db/database.dart'; | ||
|
||
Database constructDb() => throw UnimplementedError(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.