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!

ots's People

Contributors

allcontributors[bot] avatar ddurzo avatar fayaz07 avatar imgbotapp avatar pranathireddyk avatar toniremi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ots's Issues

Flutter 2 Null Safety support

Hey there,
Are there any plans to get null-safety support for this library?
I am using it as a crucial dependency in my project and due to the "connectivity" package still using old dependencies, it is causing bugs in running pub-update.
Thanks

Migration guide from progress_dialog to otis?

Is there a guide or can you tell me how I can migrate this code to OTS?

  ProgressDialog _contextProgressDialog({required BuildContext context}) {
    var dialog = ProgressDialog(context, type: ProgressDialogType.Normal, isDismissible: false, showLogs: false);
    dialog.style(
      messageTextStyle:
          TextWidgetComposer.montserratStyle(fontSize: 16.0, fontColor: Colors.black, fontWeight: FontWeight.w600),
      backgroundColor: Colors.white,
      progressWidget: ImageWidgetComposer.myCustomLoaderAnimatedImage(),
      insetAnimCurve: Curves.decelerate,
    );

    return dialog;
  }

using queue to show overlays

when user requests for multiple overlays to be displayed simultaneously, then plugin should handle a queue and show them in fifo order without losing the message

[_hideOverlay] throws if no overlay is currently shown

When hiding an overlay which is not currently showing an error is assertion fails package:flutter/src/widgets/overlay.dart': Failed assertion: line 134 pos 12: '_overlay != null': is not true

There's currently (as far as I can see) no facility to check for the presence of an overlay which means a user can not make assertions about the presence of a specific overlay type before calling a hideX functiojn. If there was; as the hideX functions are async, this could lead to race conditions if an assertion returns true before the _hideOverlay function has set the set the overlay as hidden.

This is currently caught, logged, and then re-thrown within

Future<void> _hideOverlay(_OverlayType type) async {

Given the fact that this function can not provide a strong assertion about whether or not an overlay is actually hidden or not it would be useful for the _hideOverlay function to assert on the visibility of an overlay before calling OverlayEntry.remove() so that hideX functions can be called multiple times and if an overlay of that type is not shown, they will do nothing.

In my opinion the ability to call the hide functions multiple times without causing errors is very useful, particularly with the Loader type as in most cases it's preferable to ensure that a loader is eventually removed rather than an app ending up in a dead state.

Relevant Stack:

/flutter ( 7235): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 134 pos 12: '_overlay != null': is not true.
E/flutter ( 7235): #0      hideLoader (package:ots/ots.dart:199:5)
E/flutter ( 7235): <asynchronous suspension>
E/flutter ( 7235): #1      _App.build.<anonymous closure> (package:troglo/main.dart:52:13)
E/flutter ( 7235): <asynchronous suspension>
E/flutter ( 7235): #2      _App.build.<anonymous closure> (package:troglo/main.dart)
E/flutter ( 7235): #3      GetMaterialApp.build.<anonymous closure> (package:get_navigation/src/root/root_widget.dart:203:19)
E/flutter ( 7235): #4      _GetBuilderState.initState (package:get_state_manager/src/simple/get_state.dart:168:51)
E/flutter ( 7235): #5      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
E/flutter ( 7235): #6      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 7235): #7      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 7235): #8      Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 7235): #9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter ( 7235): #10     Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter ( 7235): #11     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter ( 7235): #12     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 7235): #13     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 7235): #14     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 7235): #15     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter ( 7235): #16     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 7235): #17     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 7235): #18     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter ( 7235): #19     Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter ( 7235): #20     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter ( 7235): #21     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 7235): #22     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 7235): #23     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 7235): #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter ( 7235): #25     Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter ( 7235): #26     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter ( 7235): #27     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 7235): #28     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 7235): #29     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 7235): #30     RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1174:16)
E/flutter ( 7235): #31     RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1145:5)
E/flutter ( 7235): #32     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1087:17)
E/flutter ( 7235): #33     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:19)
E/flutter ( 7235): #34     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1086:13)
E/flutter ( 7235): #35     WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:927:7)
E/flutter ( 7235): #36     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:908:7)
E/flutter ( 7235): #37     _rootRun (dart:async/zone.dart:1182:47)
E/flutter ( 7235): #38     _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 7235): #39     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 7235): #40     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 7235): #41     _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 7235): #42     _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 7235): #43     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter ( 7235): #44     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 7235): #45     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter ( 7235): #46     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter ( 7235): #47     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

RenderFlex overflowed when adding a longer text to any of the toasts type but normal

When adding a longer text to the toast for any type with an icon (any type but normal) the widget gets a RenderFlex overflowed error and the text overflows on the right side of the toast.

To replicate simply add a text longer than 50 characters in length to any toast of type info, error, warning or success.

Here are some screenshots that may show this with better detail:

error_toast_render_overflow | warning_toast_render_overflow

Here it is how this same text looks on the normal toast:

normal_tost_no_overflow

I am working on a solution already and may send a pull request once solved but I wanted to open issue just in case to keep track of it.

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.