mmd_ecommerce_fl_lib 0.0.8 copy "mmd_ecommerce_fl_lib: ^0.0.8" to clipboard
mmd_ecommerce_fl_lib: ^0.0.8 copied to clipboard

outdated

It is a backend library using GraphQl to facilitate connection to our different e-commerce backend endpoints.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:mmd_ecommerce_fl_lib/mmd_ecommerce.dart';
import 'package:mmd_ecommerce_fl_lib_example/screens/address_screen.dart';
import 'package:mmd_ecommerce_fl_lib_example/screens/general_screen.dart';
import 'package:mmd_ecommerce_fl_lib_example/screens/main_second.dart';

import 'apis/auth_apis.dart';
import 'apis/user_apis.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    MmdECommerceFlLib.submitBaseUrl("http://egfoods.moselaymdserver.com");
    MmdECommerceFlLib.submitLanguage(Languages.arabic);
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var isLoading = false;
  AuthPayload auth;
  var isError = false;

  TextEditingController emailController = TextEditingController();
  TextEditingController codeController = TextEditingController();
  TextEditingController passwordController = TextEditingController();

  @override
  void initState() {
    print("init state");
    // Future.delayed(Duration(microseconds: 0)).then((value) => callApi());
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('GraphQl Demo'),
        ),
        body: Center(child: isLoading ? getLoadingView() : getNormalView()));
  }

  callApi() async {
    setState(() {
      isLoading = true;
    });
    AuthApiManager.loginApi('test@mail.com', '123456789',
        (AuthPayloadLogin auth) {
      setState(() {
        this.isLoading = false;
        this.auth = auth.authPayload;
      });
    }, () {
      this.isError = true;
    });
  }

  Widget getLoadingView() {
    return CircularProgressIndicator();
  }

  Widget getNormalView() {
    if (isError) {
      return Text("Result Error");
    } else {
      return Column(
        children: [
          Text("Result Success \n${auth?.access_token}"),
          RaisedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) => MainSecond(auth.refresh_token)),
              );
            },
            child: Text("Open Main Second"),
          ),
          RaisedButton(
            color: Colors.amber,
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => AddressScreen()),
              );
            },
            child: Text("Open Address Scren"),
          ),
          RaisedButton(
            color: Colors.blueAccent,
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => GeneralScreen()),
              );
            },
            child: Text("Open General Scren"),
          ),
          RaisedButton(
            color: Colors.amber,
            onPressed: () {
              callLoginApi();
            },
            child: Text("Test login"),
          ),
          RaisedButton(
            color: Colors.brown,
            onPressed: () {
              callUpdateProfileApi(emailController.text, codeController.text);
            },
            child: Text(
              "update Profile",
              style: TextStyle(color: Colors.white),
            ),
          ),
          RaisedButton(
            color: Colors.redAccent,
            onPressed: () {
              callMyProfileApi();
            },
            child: Text(
              "get profile",
              style: TextStyle(color: Colors.white),
            ),
          ),
          TextField(
            controller: emailController,
            decoration: InputDecoration(hintText: "email"),
          ),
          TextField(
            controller: codeController,
            decoration: InputDecoration(hintText: "code"),
          ),
          TextField(
            controller: passwordController,
            decoration: InputDecoration(hintText: "password"),
          ),
          RaisedButton(
            color: Colors.green,
            onPressed: () {
              callRegisterApi();
            },
            child: Text(
              "Register User",
              style: TextStyle(color: Colors.white),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              RaisedButton(
                color: Colors.black,
                onPressed: () {
                  callForgetPasswordApi(emailController.text);
                },
                child: Text(
                  "Forgot Pass",
                  style: TextStyle(color: Colors.white),
                ),
              ),
              RaisedButton(
                color: Colors.black,
                onPressed: () {
                  callResetPasswordApi(emailController.text,
                      passwordController.text, codeController.text);
                },
                child: Text(
                  "Reset Pass",
                  style: TextStyle(color: Colors.white),
                ),
              )
            ],
          )
        ],
      );
    }
  }

  callLoginApi() async {
    await AuthApiManager.loginApi("test@mail.com", "123456789",
        (AuthPayloadLogin authPayload) async {
      auth = authPayload.authPayload;
      MmdECommerceFlLib.submitTokeAndTokenType(
          authPayload.authPayload.access_token,
          authPayload.authPayload.token_type);
      print("=========================================");
      print("Success Login");
      print("Access Token: ${authPayload.authPayload.access_token}");
    }, (QueryResult x) {
      print("error");
    });
  }
}
2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

It is a backend library using GraphQl to facilitate connection to our different e-commerce backend endpoints.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, artemis, equatable, flutter, gql, graphql_flutter, json_annotation, json_serializable, meta, path_provider

More

Packages that depend on mmd_ecommerce_fl_lib