Giter Club home page Giter Club logo

ots's Introduction

over-the-screen

All Contributors

LinkedIn   Fork   Star   Watches

Get the library   Example

Buy Me A Coffee

An widget that can show loaders, notifications, internet connectivity changes as Overlay.

Screenshots

Demo

Internet connectivity changes Loader Notification

default_toast error_toast info_toast success_toast warning_toast

Installation

dependencies:
  flutter:
    sdk: flutter
  ...

  ots:
    git:
      url: git://github.com/fayaz07/ots.git

How to use

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OTS(
      showNetworkUpdates: true,
      persistNoInternetNotification: false,

      /// pass your custom loader here
      loader: CircularProgressIndicator(
        valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
      ),

      child: MaterialApp(
      title: 'OTS Test',
        home: Home(),
      ),
    );
  }
}

By default, loader is set to CircularProgressIndicator for Android and CupertinoActivityIndicator for iOS.

Showing and hiding a loader

showLoader(
  isModal: true,
);
/// Your network operation
hideLoader();

Note: isModal stops user from interacting with the screen

Showing and hiding a notification

showNotification(
  title: 'Test',
  message: 'Hello, this is notification',
  backgroundColor: Colors.green,
  autoDismissible: true,
  notificationDuration: 2500,
);

// use only if `autoDismissible: false`
hideNotification();

Showing toasts

Default toast
bakeToast("Hey toast!");
Info toast
bakeToast("Hey info!", type: ToastType.info);
Success toast
bakeToast("Hey success!", type: ToastType.success);
Error toast
bakeToast("Hey error!", type: ToastType.error);
Warning toast
bakeToast("Hey warning!", type: ToastType.warning);

Note: Notifications are automatically dismissed after the specified duration if autoDismissible is set to true.

Customize network updates messages and colors

You can customize text and color of network update messages to support multi-language applications. To do that, you must create a new class that extends NetworkStateMessenger

class CustomNetworkStateMessage extends NetworkStateMessenger {
  @override
  String message(NetworkState? networkState) {
    switch (networkState) {
      case NetworkState.Connected:
        return '#YOUR_CONNECTED_CUSTOM_MESSAGE#';
      case NetworkState.Disconnected:
        return '#YOUR_DISCONNECTED_CUSTOM_MESSAGE#';
      case NetworkState.Weak:
        return '#YOUR_WEAK_CUSTOM_MESSAGE#';
      case null:
    }
    return '#YOUR_UNKNOWN_CUSTOM_MESSAGE#';
  }

  @override
  Color color(NetworkState? networkState) {
    switch (networkState) {
      case NetworkState.Connected:
        return Colors.lightGreen;
      case NetworkState.Disconnected:
        return Colors.red;
      case NetworkState.Weak:
        return Colors.yellow;
      case null:
    }
    return Colors.orange;
  }
}

and then configure this custom messenger in the OTS constructor

return OTS(
  ...
  showNetworkUpdates: true,
  persistNoInternetNotification: true,
  networkStateMessenger: CustomNetworkStateMessage(),
  ...
)

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Mohammad Fayaz

💻 🖋 📖 💡 🤔 🚧

Alex Deas

💻

Pranathi Reddy

💻

Aster

💻

lscbot

💻

Antoni Remeseiro Alfonso

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.