Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
/ ProviderMVC Public archive

MVC design pattern implementation using flutter Provider package as a base.

License

Notifications You must be signed in to change notification settings

aymentoumi/ProviderMVC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Provider MVC

Flutter Provider MVC Implementation.

Getting Started

This project is the base of the Flutter package provider_mvc

For more information see this article Flutter Provider MVC Implementation

Examples

Let's see some examples of MVC app.

Counter App

As a default example, we developed our version of the famous flutter counter app.

image

Step 1

Model class definition. Because our app is too basic we can even skip model declaration but for pedagogical reasons we will create one. The model can be an easy PODO (Plain Old Dart Object).

class Value {
    int value = 0;
}

Step 2

Controller class definition:

class CounterController extends Controller {
  final Value _count = Value();

  int get count => _count.value;

  void reset() {
    _count.value = 0;
    update();
  }

  void increment() {
    _count.value++;
    update();
  }
}

Step 3

View class definition.

class CounterView extends View<CounterController> {
  CounterView() : super(CounterController());

  @override
  Widget builder(
          BuildContext context, CounterController controller, Widget widget) =>
      Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            'You have pushed the button this many times:',
          ),
          Text(
            '${controller.count}',
            style: Theme.of(context).textTheme.headline4,
          ),
          RaisedButton(
            child: Text("Reset"),
            onPressed: controller.reset,
          )
        ],
      );
}

Step 4

The app class.

class CounterApp extends StatelessWidget {
  final _counter = CounterView();

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: Text('Flutter Demo Home Page'),
        ),
        body: Center(
          child: _counter,
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => _counter.controller.increment(),
          tooltip: 'Increment',
          child: Icon(Icons.add),
        ),
      );
}

Step 5

The main file.

final CounterApp counterApp = CounterApp();

void main() => runApp(
      MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: counterApp),
    );

Other examples

BG Color App

image

Bulbs App

image

Movie List App

image

Github Portfolio App

image

Project Management Board App

image

Community Feed App

image

About

MVC design pattern implementation using flutter Provider package as a base.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published