commons 0.7.8+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

Commons #

Commons Flutter package can used for Flutter Android and IOS applications.

https://pub.dev/packages/commons example/lib/main.dart

Includes

  • Alert dialog
  • Toast messages
  • Single input dialog
  • Single select dialog
  • Multi select dialog
  • Radio list dialog
  • Options dialog
  • Loading screen
  • Extensions functions
  • Stack trace screen
  • Shared Preferences functions
  • Value validators
  • Date and Time functions
  • Connection Functions
  • http rest client api functions
  • list view screen with search

How to use #

Required Dart version >= 2.6+

1. Depend on it #

Add this to your package's pubspec.yaml file:

dependencies:  
  commons: ^0.7.8+3

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
  • option dialog
  • Single select dialog
  • Multi select dialog
  • Radio list dialog

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",
    validator: (value) {
      print("Validator: $value");
      return value.isEmpty ? "Required!" : null;
    },
    positiveAction: (value) {
      print("Submit: $value");
    },
    negativeAction: () {
      print("negative action");
    },
    neutralAction: () {
      print("neutral action");
    },
);

Options dialog #

var options = List<Option>()
              ..add(Option.edit())
              ..add(Option.view())
              ..add(Option.details())
              ..add(Option.delete())
              ..add(Option.item(Text("Custom"), icon: Icon(Icons.details)));
optionsDialog(context, "Options", options);

Single select dialog #

var list = Set<SimpleItem>()
                  ..add(SimpleItem(1, "Version 1.0"))
                  ..add(SimpleItem(1, "Version 2.0"))
                  ..add(SimpleItem(1, "Version 3.0"))
                  ..add(SimpleItem(1, "Version 4.0"))
                  ..add(SimpleItem(2, "Version 5.0"))
                  ..add(SimpleItem(3, "Version 6.0"))
                  ..add(SimpleItem(4, "Version 7.0"));
singleSelectDialog(context, "Single Select", list, (item) {
  print(item);
});

Multi select dialog #

Set<SimpleItem> list = Set()
                  ..add(SimpleItem(1, "Version 1.0"))
                  ..add(SimpleItem(1, "Version 2.0"))
                  ..add(SimpleItem(1, "Version 3.0"))
                  ..add(SimpleItem(1, "Version 4.0"))
                  ..add(SimpleItem(2, "Version 5.0"))
                  ..add(SimpleItem(3, "Version 6.0"))
                  ..add(SimpleItem(4, "Version 7.0"))
                  ..add(SimpleItem(4, "Version 8.0"))
                  ..add(SimpleItem(4, "Version 9.0"))
                  ..add(SimpleItem(4, "Version 10.0"));
multiSelectDialog(
  context,
  "Multi Selects",
  list,
  _selectedItems,
  (values) {
    setState(() {
      _selectedItems = values;
    });
    print(values);
  },
);

Radio list dialog #

Set<SimpleItem> set = Set<SimpleItem>()
                  ..add(SimpleItem(1, "One"))
                  ..add(SimpleItem(2, "Two"))
                  ..add(SimpleItem(3, "Three"));
radioListDialog(
  context,
  "Select one",
  set,
  (item) {
    print(item);
  },
);

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:example/theme_changer.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<ThemeChanger>(
      create: (_) => ThemeChanger(ThemeData.light()),
      child: OKToast(
        child: MaterialAppWithTheme(),
      ),
    );
  }
}

class MaterialAppWithTheme extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final theme = Provider.of<ThemeChanger>(context);

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Commons Example',
      theme: theme.getTheme(),
      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 = "";
  Set<SimpleItem> _selectedItems = Set();

  _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) {
    ThemeChanger _themeChanger = Provider.of<ThemeChanger>(context);

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SafeArea(
        child: ListView(
          children: <Widget>[
            ListTile(
              title: Text("Light Theme"),
              onTap: () => _themeChanger.setTheme(ThemeData.light()),
            ),
            ListTile(
              title: Text("Dark Theme"),
              onTap: () => _themeChanger.setTheme(ThemeData.dark()),
            ),
            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: () {
                dialog(
                  context,
                  Colors.pink,
                  "Title",
                  "Some message",
                  false,
                  true,
                  customIcon: Icon(
                    Icons.ac_unit,
                    size: 64,
                    color: Colors.white,
                  ),
                );
              },
              title: Text("Custom Dialog"),
            ),
            ListTile(
              onTap: () {
                singleInputDialog(
                  context,
                  title: "Input Dialog",
                  label: "Name",
                  value: singleInput,
                  errorText: "Required!",
                  validator: (value) {
                    print("Validator: $value");
                    return value.isNotEmpty;
                  },
                  positiveAction: (value) {
                    print("Submit: $value");
                    setState(() {
                      singleInput = 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: () {
                List<SimpleItem> list = List()
                  ..add(SimpleItem(1, "First", remarks: "sub title"))
                  ..add(SimpleItem(2, "Second", remarks: "sub title"))
                  ..add(SimpleItem(3, "Third", remarks: "sub title"))
                  ..add(SimpleItem(4, "Forth", remarks: "sub title"));
                push(
                  context,
                  ListViewScreen(
                    "List View Example",
                    list,
                    (item, index, searchValue) {
                      return Card(
                        margin:
                            EdgeInsets.symmetric(vertical: 4, horizontal: 8),
                        elevation: 1,
                        child: ListTile(
                          onTap: () {
                            pop(context);
                            print("$item at index $index");
                          },
                          title: highlightTitleTextWidget(
                              context, item.title, searchValue),
                        ),
                      );
                    },
                    searchCriteria: (item, text) => item.title.contains(text),
                  ),
                );
              },
              title: Text("List View Screen"),
            ),
            ListTile(
              onTap: () {
                tryCatch(context, this, () {
                  throw Exception("throw exception manully...");
                });
              },
              title: Text("Stack Trace Screen"),
            ),
            ListTile(
              onTap: () {
                var options = List<Option>()
                  ..add(Option.edit())
                  ..add(Option.view())
                  ..add(Option.details())
                  ..add(Option.delete())
                  ..add(Option.item(Text("Custom"), icon: Icon(Icons.details)));
                optionsDialog(context, "Options", options);
              },
              title: Text("Options Dialog"),
            ),
            ListTile(
              onTap: () {
                var list = Set<SimpleItem>()
                  ..add(SimpleItem(1, "Version 1.0"))
                  ..add(SimpleItem(1, "Version 2.0"))
                  ..add(SimpleItem(1, "Version 3.0"))
                  ..add(SimpleItem(1, "Version 4.0"))
                  ..add(SimpleItem(2, "Version 5.0"))
                  ..add(SimpleItem(3, "Version 6.0"))
                  ..add(SimpleItem(4, "Version 7.0"));
                singleSelectDialog(context, "Single Select", list, (item) {
                  print(item);
                });
              },
              title: Text("Single select dialog"),
            ),
            ListTile(
              onTap: () {
                Set<SimpleItem> list = Set()
                  ..add(SimpleItem(1, "Version 1.0"))
                  ..add(SimpleItem(1, "Version 2.0"))
                  ..add(SimpleItem(1, "Version 3.0"))
                  ..add(SimpleItem(1, "Version 4.0"))
                  ..add(SimpleItem(2, "Version 5.0"))
                  ..add(SimpleItem(3, "Version 6.0"))
                  ..add(SimpleItem(4, "Version 7.0"))
                  ..add(SimpleItem(4, "Version 8.0"))
                  ..add(SimpleItem(4, "Version 9.0"))
                  ..add(SimpleItem(4, "Version 10.0"));
                multiSelectDialog(
                  context,
                  "Multi Selects",
                  list,
                  _selectedItems,
                  (values) {
                    setState(() {
                      _selectedItems = values;
                    });
                    print(values);
                  },
                );
              },
              title: Text("Multi select dialog"),
            ),
            ListTile(
              onTap: () {
                Set<SimpleItem> set = Set<SimpleItem>()
                  ..add(SimpleItem(1, "One"))
                  ..add(SimpleItem(2, "Two"))
                  ..add(SimpleItem(3, "Three"));
                radioListDialog(
                  context,
                  "Select one",
                  set,
                  (item) {
                    print(item);
                  },
                );
              },
              title: Text("Radio list 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.
    );
  }
}

Documentation #

For help getting started with Commons, view our online Documentation. Get complete code from Github. Author: Ch Arbaz Mateen

[0.7.8+3] #

  • Minor bugs fixed

[0.7.8+2] #

  • Minor bugs fixed

[0.7.8+1] #

  • Minor bugs fixed

[0.7.8] #

  • Upgrade to flutter stable version 1.17
  • `Navigator(context).pop()' function issues fixed
  • Minor bug fixed at Single/Multi selection dialog

[0.7.7+1] #

  • Minor bug fixed at SharedPreferences remove function

[0.7.7] #

  • highlightTitle and SubTitle function updated (title style, subtitle style)

[0.7.6] #

  • parameter confirmationText added to dialog for custom checkbox text
  • minor bug fixes

[0.7.5] #

  • Prepare for 1.0.0 version of sensors and package_info. (dart_lsc)

[0.7.4] - SingleInput Dialog Breaking Changes #

  • Breaking changes to single input dialog
  • remove errorText parameter
  • parameter validator function return string error message instead of bool
  • see example/lib/main.dart for details

[0.7.3] - Navigator Extension Functions (Bug Fixes) #

  • Navigator extension functions added for push, pop, replace, mustPop
  • Bug fixes

[0.7.2] - Navigator Extension Functions #

  • Navigator extension functions added for push, pop, replace

[0.7.1] - Theme support #

  • Add theme support to highlightTitleText, highlightSubTitleText functions

[0.7.0] - Alert dialog button color #

  • Alert dialog button color changed to accent color

[0.6.9] - Theme Support Available #

  • Theme support added

[0.6.8] - Bug fixed #

  • Bugs fixes (Single input dialog)

[0.6.7] - Bug fixed #

  • Bugs fixes (Single input dialog)

[0.6.6] - Bug fixed #

  • Bugs fixes (Single input dialog)

[0.6.5] - Minor Changes #

  • Minor Changes

[0.6.4] - Generic Dialog function #

  • Dialog function for custom icon and custom circle color

[0.6.3] - Bug fixed #

  • Minor bug fixes

[0.6.2] - Data Class #

  • Data class is no more abstract

[0.6.1] - String Extensions Function #

  • Add string extension functions toInt, toDouble

[0.6.0] - TextEditingController Extensions Function #

  • Add extension functions getText, getInt, getDouble with default value return if error

[0.5.9] - Changes #

  • Minor Changes

[0.5.8] - WIFI Icon #

  • Added wifi off icon on error dialog icons for no internet connectivity

[0.5.7] - Minor Changes #

  • Minor Changes

[0.5.6] - Bugs Fixes #

  • Minor bugs fixes

[0.5.5] - Bugs Fixes #

  • Minor bugs fixes

[0.5.4] - Minor changes #

  • Minor changes (Radio list dialog)

[0.5.3] - Radio list Dialog #

  • Added: Radio list dialog

[0.5.2] - Selection Dialogs #

  • Added: Single select dialog
  • Added: Multi select dialog

[0.5.1] - List View Screen #

  • Added: List view screen with search field

[0.5.0] - Options Dialog #

  • Options dialog added

[0.4.9] - Readme.md file update #

  • Readme.md file update

[0.4.8] - Readme.md file update #

  • Readme.md file update

[0.4.7] - Minor changes #

  • Minor changes

[0.4.6] - Bugs Fixes #

  • Bugs fixes

[0.4.5] - Bugs Fixes #

  • Bugs fixes

[0.4.4] - Bugs Fixes #

  • Bugs fixes

[0.4.3] - Bugs Fixes #

  • Bugs fixes

[0.4.2] - Single input dialog #

  • Single input dialog added

[0.4.1] - OS Version #

  • Get OS Version

[0.4.0] - Http Functions (Updated) #

  • minor changes

[0.3.9] - Http Functions #

  • http rest client api function added

[0.3.8] - Connection Functions #

  • Internet connection listener
  • Connection checker

[0.3.7] - .md file updated #

  • .md file changed

[0.3.6] - .md file updated #

  • .md file changed

[0.3.5] - Example Added #

  • Complete example added

[0.3.4] - Bug Fixed #

  • Minor bug fixed

[0.3.3] - Extension Functions #

  • Added
  • DateTime
  • integer
  • double
  • formats
  • DateTimeAPI

[0.3.2] - Functions #

  • Functions added
  • getPackageInfo()
  • getDeviceInfo()

[0.3.1] - Widget Screen #

  • Widget Screen added

[0.3.0] - Ok Toast functions #

[0.2.9] - Minor Changes #

  • Minor changes

[0.2.8] - Shared Preferences added #

  • Shared preferences added with Prefs class

[0.2.7] - Minor changes #

  • Minor changes

[0.2.6] - Add to git #

  • nothing special

[0.2.5] - Added string extension functions #

  • String extensions function added (capitalize, titleCase)
  • Navigation functions added (push, pop, replaceWith)

[0.2.4] - Added Stack Trace Dialog #

  • Stack trace dialogs is now part of commons library

[0.2.3] - Dialog bugs fixes #

  • Dialog bugs fixes

[0.2.2] - Example project added #

  • Adding example project

[0.2.1] - Formatting dialogs #

  • Formatting dialogs.

[0.2.0] - Adding dialogs #

  • Adding dialogs.

[0.1.1] - Minor changes #

  • minor changes.

[0.1.0] - Getting overall score #

  • Getting overall score.

[0.0.1] - Initial release #

  • Initial release.

example/lib/main.dart

import 'package:commons/commons.dart';
import 'package:example/theme_changer.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<ThemeChanger>(
      create: (_) => ThemeChanger(ThemeData.light()),
      child: OKToast(
        child: MaterialAppWithTheme(),
      ),
    );
  }
}

//      theme: ThemeData(
//        primarySwatch: Colors.teal,
//        primaryColorDark: Colors.teal[900],
//        accentColor: Colors.pink[600],
//      ),

class MaterialAppWithTheme extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final theme = Provider.of<ThemeChanger>(context);

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Commons Example',
      theme: theme.getTheme(),
      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 = "";
  Set<SimpleItem> _selectedItems = Set();

  _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) {
    ThemeChanger _themeChanger = Provider.of<ThemeChanger>(context);

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SafeArea(
        child: ListView(
          children: <Widget>[
            ListTile(
              title: Text("Light Theme"),
              onTap: () => _themeChanger.setTheme(ThemeData.light()),
            ),
            ListTile(
              title: Text("Dark Theme"),
              onTap: () => _themeChanger.setTheme(ThemeData.dark()),
            ),
            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: () {},
                    confirmationText: "Check this");
              },
              title: Text("Confirm Dialog"),
            ),
            ListTile(
              onTap: () {
                dialog(
                  context,
                  Colors.pink,
                  "Title",
                  "Some message",
                  false,
                  true,
                  customIcon: Icon(
                    Icons.ac_unit,
                    size: 64,
                    color: Colors.white,
                  ),
                );
              },
              title: Text("Custom Dialog"),
            ),
            ListTile(
              onTap: () {
                singleInputDialog(
                  context,
                  title: "Input Dialog",
                  label: "Name",
                  value: singleInput,
                  validator: (value) {
                    print("Validator: $value");
                    return value.isEmpty ? "Required!" : null;
                  },
                  positiveAction: (value) {
                    print("Submit: $value");
                    setState(() {
                      singleInput = 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: () {
                List<SimpleItem> list = List()
                  ..add(SimpleItem(1, "One", remarks: "sub title"))
                  ..add(SimpleItem(2, "Teo", remarks: "sub title"))
                  ..add(SimpleItem(3, "Three", remarks: "sub title"))
                  ..add(SimpleItem(4, "Four", remarks: "sub title"))
                  ..add(SimpleItem(5, "Five", remarks: "sub title"))
                  ..add(SimpleItem(6, "Six", remarks: "sub title"))
                  ..add(SimpleItem(7, "Seven", remarks: "sub title"))
                  ..add(SimpleItem(8, "Eight", remarks: "sub title"))
                  ..add(SimpleItem(9, "Nine", remarks: "sub title"));
                push(
                  context,
                  ListViewScreen(
                    "List View Example",
                    list,
                    (item, index, searchValue) {
                      return Card(
                        margin:
                            EdgeInsets.symmetric(vertical: 4, horizontal: 8),
                        elevation: 1,
                        child: ListTile(
                          onTap: () {
                            popThis();
                            print("$item at index $index");
                          },
                          title: highlightTitleTextWidget(
                              context, item.title, searchValue),
                          subtitle: highlightSubTitleTextWidget(
                              context, item.remarks, searchValue),
                        ),
                      );
                    },
                    searchCriteria: (item, text) => item.title.contains(text),
                  ),
                );
              },
              title: Text("List View Screen"),
            ),
            ListTile(
              onTap: () {
                tryCatch(context, this, () {
                  throw Exception("throw exception manully...");
                });
//                try {
//                  throw Exception("throw exception manully...");
//                } on Exception catch (e, s) {
//                  push(
//                    context,
//                    StackTraceScreen(
//                      className: runtimeType.toString(),
//                      stackTrace: "$s",
//                      errorMessage: "$e",
//                      mailTo: "arbaz.mateen@softagics.com",
//                      shareButton: true,
//                      deviceInfo: true,
//                      subject: "Stack Trace",
//                    ),
//                  );
//                } on Error catch (e, s) {
//                  push(
//                    context,
//                    StackTraceScreen(
//                      className: runtimeType.toString(),
//                      stackTrace: "$s",
//                      errorMessage: "$e",
//                      mailTo: "arbaz.mateen@softagics.com",
//                      shareButton: true,
//                      deviceInfo: true,
//                      subject: "Stack Trace",
//                    ),
//                  );
//                } catch (e, s) {
//                  push(
//                    context,
//                    StackTraceScreen(
//                      className: runtimeType.toString(),
//                      stackTrace: "$s",
//                      errorMessage: "$e",
//                      mailTo: "arbaz.mateen@softagics.com",
//                      shareButton: true,
//                      deviceInfo: true,
//                      subject: "Stack Trace",
//                    ),
//                  );
//                }
              },
              title: Text("Stack Trace Screen"),
            ),
            ListTile(
              onTap: () {
                var options = List<Option>()
                  ..add(Option.edit())
                  ..add(Option.view())
                  ..add(Option.details())
                  ..add(Option.delete())
                  ..add(Option.item(Text("Custom"), icon: Icon(Icons.details)));
                optionsDialog(context, "Options", options);
              },
              title: Text("Options Dialog"),
            ),
            ListTile(
              onTap: () {
                var list = Set<SimpleItem>()
                  ..add(SimpleItem(1, "Version 1.0"))
                  ..add(SimpleItem(1, "Version 2.0"))
                  ..add(SimpleItem(1, "Version 3.0"))
                  ..add(SimpleItem(1, "Version 4.0"))
                  ..add(SimpleItem(2, "Version 5.0"))
                  ..add(SimpleItem(3, "Version 6.0"))
                  ..add(SimpleItem(4, "Version 7.0"));
                singleSelectDialog(context, "Single Select", list, (item) {
                  print(item);
                });
              },
              title: Text("Single select dialog"),
            ),
            ListTile(
              onTap: () {
                Set<SimpleItem> list = Set()
                  ..add(SimpleItem(1, "Version 1.0"))
                  ..add(SimpleItem(1, "Version 2.0"))
                  ..add(SimpleItem(1, "Version 3.0"))
                  ..add(SimpleItem(1, "Version 4.0"))
                  ..add(SimpleItem(2, "Version 5.0"))
                  ..add(SimpleItem(3, "Version 6.0"))
                  ..add(SimpleItem(4, "Version 7.0"))
                  ..add(SimpleItem(4, "Version 8.0"))
                  ..add(SimpleItem(4, "Version 9.0"))
                  ..add(SimpleItem(4, "Version 10.0"));
                multiSelectDialog(
                  context,
                  "Multi Selects",
                  list,
                  _selectedItems,
                  (values) {
                    setState(() {
                      _selectedItems = values;
                    });
                    print(values);
                  },
                );
              },
              title: Text("Multi select dialog"),
            ),
            ListTile(
              onTap: () {
                Set<SimpleItem> set = Set<SimpleItem>()
                  ..add(SimpleItem(1, "One"))
                  ..add(SimpleItem(2, "Two"))
                  ..add(SimpleItem(3, "Three"));
                radioListDialog(
                  context,
                  "Select one",
                  set,
                  (item) {
                    print(item);
                  },
                );
              },
              title: Text("Radio list 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.
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  commons: ^0.7.8+3

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
86
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Jul 12, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Android

Because:

  • package:commons/commons.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform Linux

Because:

  • package:commons/commons.dart that imports:
  • package:share/share.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:commons/commons.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform Windows

Because:

  • package:commons/commons.dart that imports:
  • package:shared_preferences/shared_preferences.dart that declares support for platforms: Android, iOS, Linux, macOS, Web

Package does not support Flutter platform iOS

Because:

  • package:commons/commons.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform macOS

Because:

  • package:commons/commons.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: Linux

Package not compatible with SDK dart

Because:

  • commons that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
data_connection_checker ^0.3.4 0.3.4
date_format ^1.0.8 1.0.8
device_info ^0.4.2+4 0.4.2+4
flutter 0.0.0
get_version ^0.2.0+1 0.2.2
http ^0.12.1 0.12.1
intl ^0.16.1 0.16.1
oktoast ^2.3.0 2.3.2
package_info >=0.4.0+13 <2.0.0 0.4.1
progress_indicators ^0.1.4 0.1.5
share ^0.6.4+3 0.6.4+3
shared_preferences ^0.5.7 0.5.8
time ^1.2.0 1.3.0
url_launcher ^5.4.1 5.5.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
file 5.2.1
flutter_web_plugins 0.0.0
http_parser 3.1.4
meta 1.1.8 1.2.2
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_platform_interface 1.0.2
pedantic 1.9.0 1.9.2
platform 2.2.1
platform_detect 1.4.0
plugin_platform_interface 1.0.2
process 3.0.13
pub_semver 1.4.4
shared_preferences_linux 0.0.2+1
shared_preferences_macos 0.0.1+10
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
url_launcher_linux 0.0.1+1
url_launcher_macos 0.0.1+7
url_launcher_platform_interface 1.0.7
url_launcher_web 0.1.2
vector_math 2.0.8 2.1.0-nullsafety
xdg_directories 0.1.0
Dev dependencies
flutter_test