Mixin In Flutter

Mixin In Flutter :

Mixin In Flutter

model_mixin.dart

import 'package:ecommerce/resource/state_status.dart';
import 'package:get/get.dart';

class CartModelMagento extends GetxController
    with CartMixin, LocalMixin
    implements CartModel {
  @override
  void onInit() {
    super.onInit();
    addProductToCart();
  }

  String addProductToCart() {
    return super.addProductToCart();
  }
}

abstract class CartModel with CartMixin, LocalMixin {
  double getSubTotal();
}

mixin CartMixin {
  final Map<String, int> productsInCart = {};

  Map<String, dynamic> currencyRates;

  double getSubTotal() {
    return 100.0;
  }
}

mixin LocalMixin on CartMixin implements GetxController {
  var msg = ''.obs;
  String addProductToCart() {
    return msg.value = 'Order successful';
  }

  String valueChange() {
    return msg.value = 'New order added';
  }
}

splash_page.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SplashPage extends StatelessWidget {
  final _homeController = Get.put(CartModelMagento());

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: _bodyData());
  }

  _bodyData() => Obx(() {
        return SafeArea(
            child: Column(children: [
          Text(_homeController.msg.value),
          FlatButton(
              onPressed: () {
                _homeController.valueChange();
              },
              child: Text('Click Here'))
        ]));
      });
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application