项目作者: fayaz07

项目描述 :
A widget that can show loaders, notifications, internet connectivity changes as Overlay.
高级语言: Dart
项目地址: git://github.com/fayaz07/ots.git
创建时间: 2020-05-31T05:49:19Z
项目社区:https://github.com/fayaz07/ots

开源协议:Apache License 2.0

下载


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

  1. dependencies:
  2. flutter:
  3. sdk: flutter
  4. ...
  5. ots:
  6. git:
  7. url: git://github.com/fayaz07/ots.git

How to use

  1. void main() => runApp(
  2. MyApp(),
  3. );
  4. class MyApp extends StatelessWidget {
  5. @override
  6. Widget build(BuildContext context) {
  7. return OTS(
  8. showNetworkUpdates: true,
  9. persistNoInternetNotification: false,
  10. /// pass your custom loader here
  11. loader: CircularProgressIndicator(
  12. valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
  13. ),
  14. child: MaterialApp(
  15. title: 'OTS Test',
  16. home: Home(),
  17. ),
  18. );
  19. }
  20. }

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

Showing and hiding a loader

  1. showLoader(
  2. isModal: true,
  3. );
  4. /// Your network operation
  5. hideLoader();

Note: isModal stops user from interacting with the screen

Showing and hiding a notification

  1. showNotification(
  2. title: 'Test',
  3. message: 'Hello, this is notification',
  4. backgroundColor: Colors.green,
  5. autoDismissible: true,
  6. notificationDuration: 2500,
  7. );
  8. // use only if `autoDismissible: false`
  9. hideNotification();

Showing toasts

Default toast
  1. bakeToast("Hey toast!");
Info toast
  1. bakeToast("Hey info!", type: ToastType.info);
Success toast
  1. bakeToast("Hey success!", type: ToastType.success);
Error toast
  1. bakeToast("Hey error!", type: ToastType.error);
Warning toast
  1. 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

  1. class CustomNetworkStateMessage extends NetworkStateMessenger {
  2. @override
  3. String message(NetworkState? networkState) {
  4. switch (networkState) {
  5. case NetworkState.Connected:
  6. return '#YOUR_CONNECTED_CUSTOM_MESSAGE#';
  7. case NetworkState.Disconnected:
  8. return '#YOUR_DISCONNECTED_CUSTOM_MESSAGE#';
  9. case NetworkState.Weak:
  10. return '#YOUR_WEAK_CUSTOM_MESSAGE#';
  11. case null:
  12. }
  13. return '#YOUR_UNKNOWN_CUSTOM_MESSAGE#';
  14. }
  15. @override
  16. Color color(NetworkState? networkState) {
  17. switch (networkState) {
  18. case NetworkState.Connected:
  19. return Colors.lightGreen;
  20. case NetworkState.Disconnected:
  21. return Colors.red;
  22. case NetworkState.Weak:
  23. return Colors.yellow;
  24. case null:
  25. }
  26. return Colors.orange;
  27. }
  28. }

and then configure this custom messenger in the OTS constructor

  1. return OTS(
  2. ...
  3. showNetworkUpdates: true,
  4. persistNoInternetNotification: true,
  5. networkStateMessenger: CustomNetworkStateMessage(),
  6. ...
  7. )

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!