Flutter Commons Package

Commons

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

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.6.0

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",
    errorText: "Required!",
    validator: (value) {
      print("Validator: $value");
      return value.isNotEmpty;
    },
    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");

Source Credit Url : https://github.com/Arbaz-Softagics/commons

Leave a Comment

Your email address will not be published. Required fields are marked *