GithubHelp home page GithubHelp logo

hohomy / flutter_mvc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lxiuyuan/flutter_mvc

0.0 0.0 0.0 43.32 MB

flutter mvc框架

License: BSD 2-Clause "Simplified" License

Ruby 3.95% Objective-C 1.43% Kotlin 2.20% Dart 92.43%

flutter_mvc's Introduction

flutter_mvc

分离UI跟业务逻辑的框架(动静分离)

特点

  • 生命周期完善
  • 动静分离
  • 逻辑清晰
  • 提高效率
  • diff算法优化性能

INSTALL

  flutter_mvc:
    git: https://github.com/lxiuyuan/flutter_mvc.git

AndroidStudio Plugin

  • 快速生成mvc基础代码
  • 右侧维护mvc列表
  • 快速生成fluro代码
  • json to dart

开始

引用MvcMaterialApp替换MaterialApp

    MvcMaterialApp(
          home: ...,
    );

Controller

var controller=new Controller();

  • 跳转界面:controller.push(context);
  • 关闭界面: controller.pop(result);
  • 获取widget跳转:
Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
  new Controller().widget;
}));

其他组件介绍

1.Stateful:

Stateful(
  ///绑定用到的变量
  bind: ()=>[c.text],
  builder: (ctx){
    return Text(c.text);
  },
)

controller.setState((){})的时候会根据算法进行进行刷新

2.子控件获取BasePage下controller

2.1. ControllerBuild

  • 获取BasePage下的ThisController
Widget build(context){
  return ControllerBuilder(
    builder: (ThisController c) {
      return Text(c.statelessText);
    },
  );
}

2.2. BaseState:

  • 获取BasePage下的ThisController
class ThisStateful extends StatefulWidget {
  @override
  _ThisStatefulState createState() => _ThisStatefulState();
}

class _ThisStatefulState extends BaseState<ThisStateful,ThisController> {
  @override
  Widget build(BuildContext context) {
    return Text(c.text);
  }
}

3.FragmentWidget

  • 类似于淘宝切换首页、分类、购物车的组件
  • 生命周期完善
  • 需要传递controller数组

controller.dart

class MainController extends BaseController {
   
   MainController():super(MainPage());
   var fragmentController=FragmentController();
   @override
   void initState(){
       super.initState();
       
   }

   void setPage(int index){
     fragmentController.animToPage(index);
   }
   
}

view.dart

class MainPage extends BasePage<MainController> {
  var fragments = [OneController(), TwoController()];

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: <Widget>[
          Expanded(
              child: FragmentWidget(
            controller: c.fragmentController,
            children: fragments,
          )),
          Row(
            children: <Widget>[
              Expanded(
                  child: FlatButton(
                      onPressed: () {
                        c.setPage(0);
                      },
                      child: Text("OnePage"))),
              Expanded(
                  child: FlatButton(
                      onPressed: () {
                        c.setPage(1);
                      },
                      child: Text("TwoPage"))),
            ],
          )
        ],
      ),
    );
  }
}

管理组件MvcManager:

  • Mvc
  • 可以获取到app全部的BaseController
  • current:获取当前显示的Controller

example

flutter_mvc's People

Contributors

dingjinyu7 avatar lxiuyuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.