Android manages multiple flutterfragments flutter management system

Android manages multiple flutterfragments flutter management system

Flutter state framework comparison and selection

Preface

As business needs continue to iterate, status management becomes particularly important. Data-oriented page updates are an extremely effective method, but more and more businesses will lead to more and more dependencies between modules.

This picture reflects that when the page is complex, if there is centralized state control, it will appear messy and disorganized, which will be a headache especially when locating problems. Another important reason is that Flutter will report an error when debugging. It will start reporting from runApp. If there is no corresponding error output by the status manager, it is difficult to locate which data problem is caused.

This time we mainly compare the usage and global state management of Flutter-Redux and Fish-Redux to help choose the corresponding state management framework.

flutter-redux

Introduction

flutter-redux, as the official plug-in of flutter, ensures stability and continuity of post-maintenance. In terms of functionality, Flutter’s original programming method has not changed much, except that the management and refresh of data have been encapsulated.

Instructions

1. Add a global Store at the App level

final store = Store<CountState>(countReducer, initialState: CountState.initState());
  runApp(new MyApp(store));

2. Create State

@immutable
class CountState {
  final int _count;
  get count => _count;

  CountState(this._count);

  CountState.initState() : _count = 0;
}

3. Create Action

class CountAction {}

4. Create reducer

final countReducer = combineReducers<CountState>([
  TypedReducer<CountState, CountAction>(_incrementCount),
]);

CountState _incrementCount(CountState state, action) {
  return CountState(state.count + 1);
}

5. Use Connect to convert state->viewModel in the page

Center(
        child: StoreConnector<CountState,int>(
          converter: (store) => store.state.count,
          builder: (context, count) {
            return Text(
              count.toString(),
              style: Theme.of(context).textTheme.display1,
            );
          },
        ),
      )

6. Other pages call the same state

Scaffold(
      appBar: AppBar(
        title: Text('Under Screen'),
      ),
      body: Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(
              'You have pushed the button this many times:',
            ),
            StoreConnector<CountState,int>(
              converter: (store) => store.state.count,
              builder: (context, count) {
                return Text(
                  count.toString(),
                  style: Theme.of(context).textTheme.display1,
                );
              },
            ),
          ],
        ),
      ),
      floatingActionButton: StoreConnector<CountState,VoidCallback>(

        converter: (store) {
          return () => store.dispatch(CountAction());
        },
        builder: (context, callback) {
          return FloatingActionButton(
            onPressed: callback,
            child: Icon(Icons.add),
          );
        },
      ),
    )

7. Whether to update the page?

@override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is Todo &&
          runtimeType == other.runtimeType &&
          complete == other.complete &&
          task == other.task &&
          note == other.note &&
          id == other.id;
Final Results

Multi-page status sharing, and corresponding modules are updated according to data changes

fish-redux

Introduction

Produced by Xianyu, it has clear architecture levels and strong code binding, and is suitable for large-scale projects.

Usage

(Only for the global state of the flutter-redux example)

Widget fishReduxApp() {
  final AbstractRoutes routes = PageRoutes(
    pages: <String, Page<Object, dynamic>>{
      "top": FishReduxTestPage(),
      "next": FishReduxNextPage()
    },
    visitor: (String path, Page<Object, dynamic> page) {
      /// 只有特定的范围的 Page 才需要建立和 AppStore 的连接关系
      /// 满足 Page<T> ,T 是 GlobalBaseState 的子类
      if (page.isTypeof<GlobalBaseState>()) {
        /// 建立 AppStore 驱动 PageStore 的单向数据连接
        /// 1. 参数1 AppStore
        /// 2. 参数2 当 AppStore.state 变化时, PageStore.state 该如何变化
        page.connectExtraStore<GlobalCountState>(GlobalStore.store,
                (Object pagestate, GlobalCountState appState) {
              final FishReduxTestState p = pagestate;
              if (p.count != appState.count) {
                if (pagestate is Cloneable) {
                  final Object copy = pagestate.clone();
                  final FishReduxTestState newState = copy;
                  newState.count = appState.count;
                  return newState;
                }
              }
              return pagestate;
            });
      }});

  return MaterialApp(
    title: 'zhile_demo',
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: FishReduxTestPage().buildPage(null),
    onGenerateRoute: (RouteSettings settings) {
      return MaterialPageRoute<Object>(builder: (BuildContext context) {
        return routes.buildPage(settings.name, settings.arguments);
      });
    },
  );
}

This code is a global store configuration. The implementation principle of fish-redux for this scenario is that the mainStore is not only a store bound to its own page, but can also be synthesized into a public store. As shown in the code below, this store can be shared by multiple pages. Store shares between pages. Compared with the implementation of flutter-redux, it seems more convoluted.

page.connectExtraStore<GlobalCountState>(GlobalStore.store,
                (Object pagestate, GlobalCountState appState) {
              final FishReduxTestState p = pagestate;
              if (p.count != appState.count) {
                if (pagestate is Cloneable) {
                  final Object copy = pagestate.clone();
                  final FishReduxTestState newState = copy;
                  newState.count = appState.count;
                  return newState;
                }
              }
              return pagestate;
            });
      }});

Compare

flutter-redux advantages

1. Low learning threshold and less intrusive
2. It is simple and convenient to use the same State or the same Reducer on multiple pages

flutter-redux disadvantages

Since there is no definition of Effect, it is not convenient to only modify the logic or other operations that do not require refreshing the page.
After use, the complexity of the code is improved. Compared with fish-redux, the code structure is weaker, resulting in higher code maintenance costs for large projects

other
Determine whether to update

flutter-redux needs to override the == method of viewModel to determine whether the returned data is the same as the current model. If true is returned, it indicates that no update is required, and false is updated. When updating, the view used will be the new viewModel.
The approach of Fish-redux is the same, using !identical(oldState, newState) to determine whether to update, and the state needs to be forced to implement the Cloneable interface and rewrite the clone method to ensure that Update the data when it needs to be updated and ensure that the original object data is correct.

In comparison, each has its own advantages and disadvantages. Flutter-redux has a clear idea. After updating, the data is updated and reacquired. fish-redux is more pure, developers only need to pay attention to individual State.

personal opinion

In terms of implementation, flutter-redux's State is larger and closer to Redux. The State of fish-redux will be very flexible and small, and can be targeted at each module, replacing the viewmodel.

  • [

    Flutter development (6): Flutter state management

    1. StatelessWidget It is a widget that does not require state changes. It has no internal state to manage. Where AboutDialog , CircleAvator and Text are State

    ](https://blog.51cto.com/u_16113862/6278957)

    flutter ide Text subclass

  • [

    Flutter - flutter_bloc state management

    Following the previous article about Flutter - GetX state management, you will find that in fact Flutt

    ](https://blog.51cto.com/jdsjlzx/5853490)

    flutter android java ide business logic

  • [

    flutter – routing management

    Route Management Route (Route) usually refers to a page (Page) in mobile development, which is the same as the concept of Route in single-page applications in web development. Route usually refers to an Activity in Android and a ViewController in iOS. The so-called routing management is to manage how to jump between pages, which is usually also called navigation management. This is similar to native development. Whether it is Android or iOS, navigation management will maintain a routing stack, and the routing stack (push) operation will open a...

    ](https://blog.51cto.com/u_4739341/3741546)

    flutter ide ios android 入栈

  • [

    flutter state management

    Effect:

    ](https://blog.51cto.com/u_5018054/3397762)

    ide ico sed flutter

  • [

    Flutter state management

    It probably means that the BuildContext of the Home component does not contain Provider, which is the reason for this error.

    ](https://blog.51cto.com/jdsjlzx/5736035)

    flutter android ide data ico

  • [

    Flutter(8)——State management

    Table of contents Preface to this article WidgetContextStatelessWidgetStatefulWidgetStateful Widget composition StateState life cycle Life cycle Important methods Explanation of Widget's unique identity: keyInheritedWidget Preface After learning the common components of Flutter, we have a certain understanding of the use of these components. However, just understanding is not enough, because our data is dynamic, interactive, and displayed on the interface...

    ](https://blog.51cto.com/liyuanjinglyj/2978193)

    Develop mobile applications with Flutter

  • [

    How Flutter manages state

    How Flutter manages state

    ](https://blog.51cto.com/u_11359966/3543370)

    flutter

  • [

    flutter - 08 state management

    State ManagementWhat is StatelessWidge

    ](https://blog.51cto.com/u_14184703/5672179)

    flutter ide data

  • [

    Flutter state management - ScopedModel

    1. Preface Flutter has many talents

    ](https://blog.51cto.com/jdsjlzx/5536143)

    flutter android ios ico ide

  • [

    Android manages multiple flutterfragments flutter management system

    Comparison and Selection of Flutter State Framework (1) Introduction As business needs continue to iterate, state management becomes particularly important. Data-oriented page updates are an extremely effective way, but more and more businesses will lead to conflicts among various modules. There will be more and more dependence on time. This picture reflects that when the page is complex, if there is centralized state control, it will appear messy and disorganized, especially when locating problems, it will be a headache. Another important reason is that Flutter will report an error when debugging. Will start reporting from runApp, if there is no corresponding state manager output

    ](https://blog.51cto.com/u_12959/8419507)

    flutter fish data

  • [

    Flutter Pit: SafeArea Failure Problem in FlutterFragment

    Background: Recently, I have been working on the operation of multiple Flutter Fragments under multiple tabs at the bottom of Android. I encountered another pitfall: the SafeArea of ​​the flutter page in FlutterFragment failed (for a detailed introduction to safeArea, please refer to the official SafeArea...

    ](https://blog.51cto.com/u_15127590/3319063)

    flutter android data solution status bar

  • [

    Android phone flutter notification management does not allow flutter system notifications

    1. Overview Notification is an important mechanism in Flutter. In the Widget tree, each node can distribute notifications. The notifications will be passed upward along the current node (context). All parent nodes can listen for notifications through NotificationListener. In Flutter This kind of notification delivery from child to parent is called "Notification Bubbling". This is similar to user touch event bubbling, but there is one difference: notification bubbling can be terminated.

    ](https://blog.51cto.com/u_16213605/7671911)

    sed Text customization

  • [

    android manages multiple threads android thread management

    1: Android process and thread process is an instance of program running. Android has weakened the concept of process through four main components, especially at the app level, and there is basically no need to worry about issues such as communication between processes. But the essence of the program has not changed, especially in multi-tasking systems. The basic modes of event-driven software systems are as follows: The entry of the program is generally main: 1. Initialization: such as creating windows, applying for resources, etc. 2. Enter while(true) to handle various events in the loop until the process exits. The four major components are part of the carrier of the process and configure the process

    ](https://blog.51cto.com/u_16099170/6574813)

    android manages multiple threads mobile development ui java android

  • [

    android employee management android management system

    Design and implementation of personnel management system based on Android system Contents Chapter 1 Introduction 41.1 Source and background of the project 41.2 Functions of the project 4 Chapter 2 Summary design 52.1 Development tools 52.2 Eclipse development environment 52.3 Running environment 52.4 Document structure of the project 52.5 Overall design 6 Chapter 3 Detailed Implementation of the Personnel Management System 73.1 The login interface function module of the system 73.1.1 The interface xml source file of the login interface 73.1.2 The Java source file of the login interface 93.2 The functions that constitute the main page design

    ](https://blog.51cto.com/u_14273/7482012)

    android employee management android personnel management system Android source file Java

  • [

    android multiple notification services android notification management

    In recent projects, Notification needs to be used. Previous rendering: First, learn the basic knowledge about Notification. The status notification bar mainly involves two classes: Notification and NotificationManager. Notification is a notification information class, which corresponds to various attributes of the notification bar. NotificationManager: It is the management class of status bar notifications and is responsible for operations such as sending notifications and clearing notifications. Notice:

    ](https://blog.51cto.com/u_39029/7267100)

    android multiple notification services android notification control customization

  • [

    android development student management system android project student management system

    Overview: Android implements the functions of the student information management system to view course information under the name and student messages. The student ID cannot be known and the user can click to trigger the course to modify and select the score statistics of the students in the course. The course information implements the main interface - logic code package com. example.database_manage.teacher;//import has been hidden/*teacher terminal main interface*/public class activity_teacher extend

    ](https://blog.51cto.com/u_14987/7701485)

    Android development student management system ide ci listener

  • [

    Flutter | Resource Management

    The Flutter installation package will contain two parts: code and assets resources. Assets will be packaged into the program installation package and can be accessed at runtime. Common types of assets include static data, such as json, configuration files, pictures, MP3, gif, etc. For example, to load an image, use the pubspec.yaml file in Flutter to manage the required files. Before loading the image, you need to create a folder in the root directory to store the image and the image with its corresponding resolution, such as

    ](https://blog.51cto.com/u_15087081/2597229)

    Flutter

  • [

    Flutter basics – state management

    When we use the compiler to create a new Flutter application, we can see two small parts on the main interface

    ](https://blog.51cto.com/u_15064655/4359981)

    ide ico sed flutter data

  • [

    android management project management management system based on android

    This article is the design and implementation of a community property management system based on Android. Since the 1990s, with the breakthrough progress of network, communication and information technology, Internet technology has exploded and spread rapidly around the world. In this era, the mobile Internet emerged as the times require, and mobile applications for various life tools have sprung up one after another, bringing great changes to people's lives and work. The Android-based community property management system designed this time is mainly to facilitate the supervision and management of property work by community users in their daily lives. At the same time,

    ](https://blog.51cto.com/u_16099184/6692628)

    android management project management android Powered by Kingsoft Document Android User Information

  • [

    Beautiful html5 background animation html5 dynamic background effects

    In the previous tutorial, we created a text mask effect using SVG and CSS. In this tutorial, we are going to use SVG and CSS3 to show you two effects of dynamically masking text backgrounds. The first effect is that when the mouse slides over the masked text, the text background will have a rainbow background animation. The second effect is the continuous dynamic change of the masked text background, just like the lights in a disco flashing. The idea of ​​making these dynamic mask text backgrounds is very simple: create a div with a dynamic background, we will use CSS3 to draw the background and apply a CSS3 an

    ](https://blog.51cto.com/u_16213579/8419751)

    Nice html5 background animation html5 svg mask SVG animation effect ci

  • [

    Cloud native in-depth analysis of Kubernetes CNI plug-in selection and application fields k8s cni plug-in

    k8s network plug-in CNI CNI: Container Network Interface: The main function is to enable Pod resources to communicate across hosts. Flannel: the most mature and simplest choice. Calico: has good performance and the most flexibility. The current enterprise-level mainstream Canal: will The network layer provided by Flannel is integrated with Calico's network policy functionality. Weave: A unique function that simply encrypts the entire network, which will increase network overhead. Kube-route

    ](https://blog.51cto.com/u_16099256/8424250)

    ico Packet Genie

  • [

    Docker client configures self-signed certificate cert docker testlink

    Contents 1. History of Docker 2. Advantages of Docker 3. The difference between Docker and virtual machines 4. Docker architecture 5. Docker installation and accelerator configuration 5.1 Windows 10 installation Docker 5.2 Ubuntu installation Docker 5.3 CentOS installation Docker 5.4 accelerator configuration 6. Docker Common commands 6.1 Basic commands 6.2 Image management 6.3 Container management 7. Building web server Nginx7.1 Introduction to Nginx 7.2 Installation

    ](https://blog.51cto.com/u_16213573/8429762)

    docker client configuration self-signed certificate cert docker container operation and maintenance Docker

  • [

    The application of Python language in the accounting field. What are the benefits of knowing Python for accounting?

    Python is an emerging programming language. After experiencing the three-day introductory course of Fengbian Programming, it is said that after completing the course, you can crawl data from major websites through crawlers, and you can access the office through various excuses to process batch data to improve office work. Efficiency, I find it very interesting. The first time I heard this term was from the sales anxiety of major public accounts: "Accountants finally don't have to make reports all day long!", "Now 95% of finance companies are doing this quietly!" It's always like this! Exclamation mark headline party alert. Should financial professionals learn Python? My own thoughts are: I understand the current

    ](https://blog.51cto.com/u_12196/8433349)

    The application of python language in the accounting field The role of python in finance Data analysis Python python

  • [

    python Douyin live broadcast room robot Douyin uses robot to live broadcast

    I wrote an article about Kuaishou’s unmanned live broadcast some time ago. I found that many friends are very interested in the unmanned live broadcast project, so we have further explored this project. Now let’s share with you the details of this project. operate. Unmanned live broadcast technology Unmanned live broadcast does not mean that there are no people during the live broadcast, but it means that you do not need to live broadcast in real time. As long as you prepare the video in advance and pretend to be live broadcast, you can achieve the effect of 24-hour online live broadcast, that is, 24 hours a day. Live delivery can be carried out every hour. The first one: Make a promotional picture with a size of 1080*1920, or a vertical screen picture.

    ](https://blog.51cto.com/u_16213662/8433359)

    Python Douyin Live Room Robot Douyin Make Money Douyin Monetization Douyin Drainage Douyin Operation

end

Don’t leave after reading the article! ! There is also a complete advanced Android development material. The contents of this series include:

"Essential Skills for Architects to Build Foundations", "Source Code Analysis of Top 100 Android Frameworks",
"Practical Analysis of Android Performance Optimization", "Advanced Kotlin Enhancement Practice", a> "Advanced Flutter Technology", "WeChat Mini Program Development".
"Advanced Decryption of Android Advanced UI Open Source Framework", "NDK Module Development",

Attached is a full set of video materials, including interview collection, source code collection, and open source framework collection!

Insert image description here
This opportunity is too good to miss, friends in need should quickly scan the QR code to get it!

Insert image description here

Guess you like

Origin blog.csdn.net/m0_56255097/article/details/134457433