Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

commons package

commons package can used for flutter android and ios applications.

includes

  • alert dialog
  • toast messages
  • single input dialog
  • loading screen
  • extensions functions
  • stack trace screen
  • shared preferences functions
  • value validators
  • date and time functions
  • connection functions
  • http rest client api functions

how to use

required dart version >= 2.6+

1. depend on it

add this to your package’s pubspec.yaml file:

dependencies:  
  commons: ^0.4.9

2. install it

you can install packages from the command line:

with flutter:

$ flutter pub get

alternatively, your editor might support flutter pub get. check the docs for your editor to learn more.

3. import it

now in your dart code, you can use:

import 'package:commons/commons.dart';

dialogs

  • success dialog
  • error dialog
  • warning dialog
  • info dialog
  • confirmation dialog
  • wait dialog
  • single input dialog

commons package





s

how to use

success dialog

successdialog(  
    context,  
    "success message",  
    negativetext: "try again",  
    negativeaction: () {},  
    positivetext: "details",  
    positiveaction: () {},  
);

confirm dialog

confirmationdialog(
    context, 
    "confirm demo dialog", 
    positivetext: "delete", 
    positiveaction: () {}
);

single input dialog

singleinputdialog(
    context,
    title: "input dialog",
    label: "name",
    errortext: "required!",
    validator: (value) {
      print("validator: $value");
      return value.isnotempty;
    },
    positiveaction: (value) {
      print("submit: $value");
    },
    negativeaction: () {
      print("negative action");
    },
    neutralaction: () {
      print("neutral action");
    },
);

toasts

  • success toast
  • error toast
  • warning toast
  • info toast




how to use

commons used oktoast dart package please check oktoast requirements first.

successtoast("success toast");

loading screen

push(
    context,
    loadingscreen(  
        context,  
        duration: duration(  
            seconds: 5,  
        ),  
        loadingtype: loadingtype.jumping,
    ),
);

complete example

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

void main() => runapp(myapp());

class myapp extends statelesswidget {
  @override
  widget build(buildcontext context) {
    return oktoast(
      child: materialapp(
        debugshowcheckedmodebanner: false,
        title: 'commons example',
        theme: themedata(
          primaryswatch: colors.teal,
          primarycolordark: colors.teal[900],
          accentcolor: colors.pink[600],
        ),
        home: myhomepage(title: 'commons example'),
      ),
    );
  }
}

class myhomepage extends statefulwidget {
  final string title;

  myhomepage({key key, this.title}) : super(key: key);

  @override
  _myhomepagestate createstate() => _myhomepagestate();
}

class _myhomepagestate extends state<myhomepage> {
  bool _online = false;
  bool _connected = false;
  var listener;
  string singleinput = "";

  _checkinternet() async {
    listener = await connectionchecker()
        .getinstance()
        .setduration(duration(
          seconds: 1,
        ))
        .listener(
      connected: () {
        setstate(() {
          _online = true;
        });
      },
      disconnected: () {
        setstate(() {
          _online = false;
        });
      },
    );
  }

  @override
  void initstate() {
    super.initstate();
    _checkinternet();
  }

  @override
  void dispose() {
    listener.cancel();
    super.dispose();
  }

  @override
  widget build(buildcontext context) {
    return scaffold(
      appbar: appbar(
        title: text(widget.title),
      ),
      body: safearea(
        child: listview(
          children: <widget>[
            listtile(
              ontap: () {
                checkinternet().then((connected) {
                  setstate(() {
                    _connected = connected;
                  });
                });
              },
              title: text("connected: $_connected"),
              subtitle: text("click to check internet connection"),
            ),
            listtile(
              title: text("connected: $_online"),
              subtitle: text("connection listener"),
            ),
            listtile(
              ontap: () {
                var now = datetime.now();
                print("${now.format()}");
                print("${now.todatestring()}");
                print("${now.totimestring()}");
                print("${now.todatetimestring()}");
                print("${now.todatetimewithmillisecondsstring()}");
                print("sqldateformat: ${datetimeapi.sqldateformat(datetime.now())}");
                print("sqldatetimeformat: ${datetimeapi.sqldatetimeformat(datetime.now())}");
                print("sqlstartdatetimeformat: ${datetimeapi.sqlstartdatetimeformat(datetime.now())}");
                print("sqlenddatetimeformat: ${datetimeapi.sqlenddatetimeformat(datetime.now())}");
                print("formatdateonly: ${datetimeapi.formatdateonly(datetime.now())}");
                print("formattimeonly: ${datetimeapi.formattimeonly(datetime.now())}");
                print("formatdatetime: ${datetimeapi.formatdatetime(datetime.now())}");
                print("lastdateofmonth: ${datetimeapi.lastdateofmonth()}");
                print("firstdateofmonth: ${datetimeapi.firstdateofmonth()}");
                print("add: ${datetimeapi.add(datetime.now(), duration(days: 5))}");
                print("subtract: ${datetimeapi.subtract(datetime.now(), duration(days: 5))}");
                print("addday: ${datetimeapi.addday(datetime.now(), 5)}");
                print("subtractday: ${datetimeapi.subtractday(datetime.now(), 5)}");
                print("addmonth: ${datetimeapi.addmonth(datetime.now(), 1)}");
                print("subtractmonth: ${datetimeapi.subtractmonth(datetime.now(), 1)}");
                print("difference: ${datetimeapi.difference(datetime.now(), datetime.now() + duration(days: 5)).indays}");

                print("numbers");
                int i = 123456;
                double a = 123456.566;
                print(i.format());
                print(a.format());
              },
              title: text("datetime test (see the log)"),
            ),
            listtile(
              ontap: () {
                successdialog(context, "success demo dialog");
              },
              title: text("success dialog"),
            ),
            listtile(
              ontap: () {
                errordialog(
                  context,
                  "contrary to popular belief, lorem ipsum is not simply random text. it has roots in a piece of classical latin literature from 45 bc, making it over 2000 years old. richard mcclintock, a latin professor at hampden-sydney college in " +
                      "virginia, looked up one of the more obscure latin words, consectetur, from a lorem ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. lorem ipsum comes from sections 1.10.32 and 1.10.33 of de " +
                      "finibus bonorum et malorum (the extremes of good and evil) by cicero, written in 45 bc. this book is a treatise on the theory of ethics, very popular during the renaissance. the first line of lorem ipsum, lorem ipsum dolor sit amet.., comes from a line in section 1.10.32." +
                      "the standard chunk of lorem ipsum used since the 1500s is reproduced below for those interested. sections 1.10.32 and 1.10.33 from de finibus bonorum et malorum by cicero are also reproduced in their exact original form, accompanied by english versions from "
                          "the 1914 translation by h. rackham.",
                  negativetext: "try again",
                  negativeaction: () {},
                  positivetext: "details",
                  positiveaction: () {},
                );
              },
              title: text("error dialog"),
            ),
            listtile(
              ontap: () {
                warningdialog(context, "warning demo dialog");
              },
              title: text("warning dialog"),
            ),
            listtile(
              ontap: () {
                infodialog(context, "info demo dialog");
              },
              title: text("info dialog"),
            ),
            listtile(
              ontap: () {
                confirmationdialog(context, "confirm demo dialog", positivetext: "delete", positiveaction: () {});
              },
              title: text("confirm dialog"),
            ),
            listtile(
              ontap: () {
                singleinputdialog(
                  context,
                  title: "input dialog",
                  label: "name",
                  errortext: "required!",
                  validator: (value) {
                    print("validator: $value");
                    return value.isnotempty;
                  },
                  positiveaction: (value) {
                    print("submit: $value");
                  },
                  negativeaction: () {
                    print("negative action");
                  },
                  neutralaction: () {
                    print("neutral action");
                  },
                );
              },
              title: text("single input dialog"),
              subtitle: text("$singleinput"),
            ),
            listtile(
              ontap: () {
                waitdialog(context, duration: duration(seconds: 3));
              },
              title: text("wait dialog"),
            ),
            listtile(
              ontap: () {
                trycatch(context, this, () {
                  throw exception("throw exception manully...");
                });
              },
              title: text("stack trace dialog"),
            ),
            listtile(
              ontap: () {
                successtoast("success toast");
              },
              title: text("success toast"),
            ),
            listtile(
              ontap: () {
                errortoast("error toast");
              },
              title: text("error toast"),
            ),
            listtile(
              ontap: () {
                warningtoast("warning toast");
              },
              title: text("warning toast"),
            ),
            listtile(
              ontap: () {
                infotoast("info toast");
              },
              title: text("info toast"),
            ),
            listtile(
              ontap: () {
                push(
                  context,
                  loadingscreen(
                    context,
                    duration: duration(
                      seconds: 5,
                    ),
                    loadingtype: loadingtype.jumping,
                  ),
                );
              },
              title: text("loading screen"),
            ),
            listtile(
              ontap: () {
                getpackageinfo().then((info) {
                  infodialog(context, info, textalign: textalign.start);
                });
              },
              title: text("package info dialog"),
            ),
            listtile(
              ontap: () {
                getdeviceinfo().then((info) {
                  infodialog(context, info, textalign: textalign.start);
                });
              },
              title: text("device info dialog"),
            ),
          ],
        ),
      ), // this trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.