MichaelMarner/dart-redux-remote-devtools
Remote Devtools for Dart & Flutter
baixar do githubRedux Remote Devtools for Dart and Flutter
Redux Remote Devtools support for Dart and Flutter.
Installation
Add the library to pubspec.yaml:
dependencies:
redux_remote_devtools: ^2.0.0
Middleware configuration
Add the middleware to your Redux configuration:
var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000');
final store = new DevToolsStore<AppState>(searchReducer,
middleware: [
remoteDevtools,
]);
remoteDevtools.store = store;
await remoteDevtools.connect();
:warning: Using mutliple middleware?
If you use other middleware, RemoteDevTools must be put last. Otherwise,
actions and state updates will be out of sync
What’s going on here?
-
Create a new instance of the devtools middleware. Specify the host and port to connect to.
-
Wait for devtools to connect to the remotedev server
-
Initialise your store. To take advantage of time travel, you should use a DevToolsStore. Pass in remoteDevTools with the rest of your middlware
-
The middleware needs a reference to the store you just created, so commands from devtools can be dispatched. So as a final step, set the reference.
Using remotedev
Use the Javascript Remote Devtools package. Start the remotedev server on your machine
npm install -g remotedev-server
remotedev --port 8000
Run your application. It will connect to the remotedev server. You can now debug your redux application by opening up http://localhost:8000
in a web browser.
Encoding Actions and State
In the Javascript world, Redux follows a convention that your redux state is a plain Javascript Object, and actions are also Javascript objects that have a type
property. The JS Redux Devtools expect this. However, Redux.dart tries to take advantage of the strong typing available in Dart. To make Redux.dart work with the JS devtools, we need to convert actions and state instances to JSON before sending.
Remember that the primary reason for using devtools is to allow the developer to reason about what the app is doing. Therefore, exact conversion is not strictly necessary - it’s more important for what appears in devtools to be meaningful to the developer.
Enconding Strategy for Actions
We use the class name as the action type
for class based actions. For enum typed actions, we use the value of the action. For example:
enum EnumActions {
Action1;
Action2;
}
class ClassAction {}
When converted, these actions will be {"type": "Action1"}
or {"type": "ClassAction"}
, etc.
We also want to send the action properties over to devtools. To do this, we attempt to jsonEncode
the entire Action, and attach this JSON data as a payload
property. For example:
class ClassAction {
int someValue;
toJson() {
return {'someValue': this.someValue};
}
}
Would appear in devtools as:
{
"type": "ClassAction",
"payload": {
"someValue": 5 // or whatever someValue was set to
},
}
This of course means your Actions need to be json encodable. You can do what the example above does and write your own toJson
method. However, a better approach is to use a generator like json_serializable to do it for you. If your action is not json encodable, the payload property will be missing in devtools.
Encoding strategy for State
For state, we simply attempt to jsonEncode
the entire thing. If your state cannot be converted, then state updates will not appear in devtools.
Overriding these strategies
The strategy described above should work for most cases. However, if you want to do something different, you can replace the ActionEncoder
and StateEncoder
with your own implementations:
var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000', actionEncoder: MyCoolActionEncoder);
Making your actions and state json encodable
You can either write your own toJson
methods for each of your actions and your state class. However, this quickly becomes cumbersome and error prone. Instead, the recommended way is to make use of the json_annotation
package to automatically generate toJson functions for you.
Dispatching Actions from DevTools
You are able to dispatch actions from the Devtools UI and have these processed by the redux implementation in your Flutter app.
In order for this to work, you need to implement an ActionDecoder
. ActionDecoder’s job is to take the JSON data received from the Devtools UI, and return an action that your reducers know how to use. For example if we dispatch an action:
{
"type": "INCREMENT"
}
We would implement an ActionDecoder like so:
ActionDecoder myDecoder = (dynamic payload) {
final map = payload as Map<String, dynamic>;
if (map['type'] == 'INCREMENT') {
return IncrementAction();
}
};
Essentially, you need to map every JSON action type into an action that can be used by your reducers.
Please get in touch if you have any awesome ideas for how to make this process smoother.
Example Apps
This repo includes remote-devtools enabled versions of the flutter-redux example apps:
-
flutter-redux Simple Counter App.
- Demonstrates how enum actions are sent to devtools.
- Shows how time travel works.
-
flutter-redux Github Search App.
-
Demonstrates how class based actions and nested state objects are serialised and made browseable in devtools
-
Demonstrates the limits of time travel in apps that use epics
-
![](/images/banner-woo.jpg)
recomendações de excelentes projetos relacionados a MichaelMarner/dart-redux-remote-devtools para download
AppFlowy
47859
AppFlowy is an open-source alternative to Notion. You are in charge of your data and customizations. Built with Flutter and Rust.
localsend
33797
An open-source cross-platform alternative to AirDrop
spotube
23772
🎧 Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
revanced-manager
15035
💊 Application to use ReVanced on Android
gsy_github_app_flutter
14559
Flutter 超完整的开源项目,功能丰富,适合学习和日常使用。GSYGithubApp系列的优势:我们目前已经拥有Flutter、Weex、ReactNative、kotlin 四个版本。 功能齐全,项目框架内技术涉及面广,完成度高,持续维护,配套文章,适合全面学习,对比参考。跨平台的开源Github客户端App,更好的体验,更丰富的功能,旨在更好的日常管理和维护个人Github,提供更好更方便的驾车体验Σ( ̄。 ̄ノ)ノ。同款Weex版本 : https://github.com/CarGuo/GSYGithubAppWeex 、同款React Native版本 : https://github.com/CarGuo/GSYGithubApp 、原生 kotlin 版本 https://github.com/CarGuo/GSYGithubAppKotlin
dio
12249
A powerful HTTP client for Dart and Flutter, which supports global settings, Interceptors, FormData, aborting and canceling a request, files uploading and downloading, requests timeout, custom adapters, etc.
gopeed
11832
A modern download manager that supports all platforms. Built with Golang and Flutter.
bloc
11441
A predictable state management library that helps implement the BLoC design pattern
getx
9899
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
flame
8846
A Flutter based game engine.
flutter_deer
7595
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project (including integration testing and accessibility testing). Contains complete UI design drawings for a more realistic practice project.
fish-redux
7343
An assembled flutter application framework.
fl_chart
6451
FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
pixez-flutter
6360
一个支持免代理直连及查看动图的第三方Pixiv flutter客户端
Flutter-Responsive-Admin-Panel-or-Dashboard
6355
Responsive Admin Panel or Dashboard using Flutter
aidea
6021
AIdea 是一款支持 GPT 以及国产大语言模型通义千问、文心一言等,支持 Stable Diffusion 文生图、图生图、 SDXL1.0、超分辨率、图片上色的全能型 APP。
riverpod
5828
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
pikapika
5463
美观易用且无广告的漫画和游戏客户端,同时支持MacOS,Windows,Android,iOS。
provider
5029
InheritedWidgets, but simple
getwidget
4416
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.