mc 0.0.1+4 copy "mc: ^0.0.1+4" to clipboard
mc: ^0.0.1+4 copied to clipboard

discontinued
outdated

State management & request package, Model,View,Request [MVR].

mc #

State management and request package, Model,View,Request [MVR].

Author: Mohammed CHAHBOUN #

Pub License: MIT

Getting Started #

In your flutter project, add the dependency to your pubspec.yaml

dependencies:
  ...
  mc: ^0.0.1+4

for generate The appropriate model by json data use this website https://json2dart.web.app/

Usage #

/////////////////////////////-- Model --/////////////////////////////
import 'package:mc/mc.dart';

class Post extends McModel{
 List multi;
 int userId;
 int id;
 String title;
 String body;

 Post({
  this.userId,
  this.id,
  this.title,
  this.body,
 }){
  multi = multi ?? [];
}


fromJson(Map<String, dynamic> json) {
  userId = json['userId'] ?? userId;
  id = json['id'] ?? id;
  title = json['title'] ?? title;
  body = json['body'] ?? body;
  return super.fromJson(json);
 }


 Map<String, dynamic> toJson() {
 final Map<String, dynamic> data = new Map<String, dynamic>();
  data['userId'] = this.userId;
  data['id'] = this.id;
  data['title'] = this.title;
  data['body'] = this.body;

  return data;
 }

void setMulti(List d) {
  List r = d.map((e) {
    Post m = Post();
    m.fromJson(e);
    return m;
      }).toList();
      multi = r;
    }

}

//Controller of your main model
//if you need more controller you can copy this and use it
        
class PostC {
  static final PostC _postC = PostC._internal();
  Post post = Post();
  factory PostC() {
    return _postC;
  }
  //you can add more methods here
  //any action on multi list you need to call rebuild method from your model for rebuild widgets
  PostC._internal();
}


/////////////////////////////-- View --/////////////////////////////
import 'package:mc/mc.dart';
import 'Request.dart';
import 'PostModel.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MVR Package',
      theme: ThemeData(
        primaryColor: Colors.brown,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'MVR Package'),
    );
  }
}

class PostExample extends StatelessWidget {
  PostExample({this.title});
  final String title;
  final PostC _con = PostC();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: FutureBuilder(
            future: request.getObjData("posts", _con.post, multi: true),
            builder: (BuildContext __, _) {
              return ListView.builder(
                itemCount: _con.post.multi.length,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(
                    leading: Text(_con.post.multi[index].id.toString()),
                    title: Text(_con.post.multi[index].title),
                    onTap: () => Navigator.of(context).push(
                        MaterialPageRoute(builder: (BuildContext context) {
                      return Details(index);
                    })),
                  );
                },
              );
            },
          )),
    );
  }
}

class Details extends StatelessWidget {
  final int index;
  Details(this.index);
  final PostC _con = PostC();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ListTile(
          leading: Text(_con.post.multi[index].id.toString()),
          title: Text(_con.post.multi[index].title),
          subtitle: Text(_con.post.multi[index].body),
        ),
      ),
    );
  }
}
/////////////////////////////-- Request --/////////////////////////////
import 'package:mc/mc.dart';
//your url without http or https and also without any /

String baseUrl = 'jsonplaceholder.typicode.com';

McRequest request = McRequest(url: baseUrl);

License #

MIT License

Copyright (c) 2021 Mohammed CHAHBOUN

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20
likes
0
pub points
8%
popularity

Publisher

unverified uploader

State management & request package, Model,View,Request [MVR].

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http

More

Packages that depend on mc