{"id":13549806,"url":"https://github.com/OpenFlutter/flutter_oktoast","last_synced_at":"2025-04-02T23:31:06.978Z","repository":{"id":33189308,"uuid":"143130553","full_name":"OpenFlutter/flutter_oktoast","owner":"OpenFlutter","description":"Toast library for Flutter.","archived":false,"fork":false,"pushed_at":"2024-12-25T07:04:40.000Z","size":348,"stargazers_count":506,"open_issues_count":3,"forks_count":58,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-12-25T08:21:24.307Z","etag":null,"topics":["dart","flutter","pub","toast","widget"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/oktoast","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenFlutter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-01T08:58:35.000Z","updated_at":"2024-12-25T07:04:44.000Z","dependencies_parsed_at":"2024-12-25T08:21:08.652Z","dependency_job_id":"ef2cacc6-da9c-4b51-bd32-59a5f753e0d5","html_url":"https://github.com/OpenFlutter/flutter_oktoast","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFlutter%2Fflutter_oktoast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFlutter%2Fflutter_oktoast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFlutter%2Fflutter_oktoast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFlutter%2Fflutter_oktoast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenFlutter","download_url":"https://codeload.github.com/OpenFlutter/flutter_oktoast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246910913,"owners_count":20853652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","pub","toast","widget"],"created_at":"2024-08-01T12:01:25.745Z","updated_at":"2025-04-02T23:31:06.481Z","avatar_url":"https://github.com/OpenFlutter.png","language":"Dart","readme":"# oktoast\n\n[![oktoast](https://img.shields.io/badge/OpenFlutter-OKToast-blue.svg)](https://github.com/OpenFlutter/flutter_oktoast)\n[![pub package](https://img.shields.io/pub/v/oktoast.svg)](https://pub.dartlang.org/packages/oktoast)\n![GitHub](https://img.shields.io/github/license/OpenFlutter/flutter_oktoast.svg)\n[![GitHub stars](https://img.shields.io/github/stars/OpenFlutter/flutter_oktoast.svg?style=social\u0026label=Stars)](https://github.com/OpenFlutter/flutter_oktoast)\n\nA library for flutter.\n\nA pure dart toast Library.\n\nYou can completely customize the style of toast.\n\n[中文博客介绍](https://www.kikt.top/posts/flutter/toast/oktoast/)\n\n## Screenshot\n\n| Default                                                                                | Custom                                                                                 | GIF                                                                                 |\n|----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|\n| ![pic](https://raw.githubusercontent.com/CccFans/images/master/img/20181207161700.png) | ![pic](https://raw.githubusercontent.com/CccFans/images/master/img/20181207161742.png) | ![pic](https://raw.githubusercontent.com/CaiJingLong/some_asset/master/ktoast2.gif) |\n\n## Versions\n\n### 3.x.x\n\nStarting from the 3.x version, OKToast provides a null-safety version,\nthe specific introduction of null-safety can be viewed in [dart][dart-safe] or [flutter][flutter-safe].\n\n[flutter-safe]: https://flutter.dev/docs/null-safety\n[dart-safe]: https://dart.dev/null-safety\n\nThe 2.3.2 version is the last version that does not support null-safety.\n\n### About version 1.x\n\nif you use OKToast 1.x, Please use the 1.x branch, and read version readme.\n\nProposed migration to 2.x version. The new version does not require buildContext.\n\nAnd you can completely customize the style of toast, because now you can use `showToastWidget`.\n\n## Usage\n\n### 1. Add library to your pubspec.yaml\n\n```shell\nflutter pub add oktoast\n```\n\n### 2. Import library in dart file\n\n```dart\nimport 'package:oktoast/oktoast.dart';\n```\n\n### 3. Wrap your app widget\n\n```dart\nOKToast(\n  /// set toast style, optional\n  child:MaterialApp()\n);\n```\n\nTips:\nIf you happened error like: `No MediaQuery widget found`,\nyou can try to use this [code](https://github.com/OpenFlutter/flutter_oktoast/issues/53#issuecomment-628431625)\nto include `OKToast` to your App.\n\n```dart\nMaterialApp(\n  builder: (BuildContext context, Widget? widget) {\n    return OKToast(child: widget);\n  },\n);\n```\n\n### 4. Call method `showToast`\n\n```dart\nshowToast('content');\n\n// position and second have default value, is optional\nshowToastWidget(Text('hello oktoast'));\n```\n\n## Explain\n\nThere are two reasons why you need to wrap MaterialApp\n\n1. Because this ensures that toast can be displayed in front of all other controls\n2. Context can be cached so that it can be invoked anywhere without passing in context\n\n## Properties\n\n### OKToast params\n\nOKToast have default style, and you also can custom style or other behavior.\n\n|         name         |          type           |   need   |                             desc                              |\n|:--------------------:|:-----------------------:|:--------:|:-------------------------------------------------------------:|\n|        child         |         Widget          | required |                     Usually Material App                      |\n|      textStyle       |        TextStyle        | optional |                                                               |\n|        radius        |         double          | optional |                                                               |\n|   backgroundColor    |          Color          | optional |                        backroundColor                         |\n|       position       |      ToastPosition      | optional |                                                               |\n|  dismissOtherOnShow  |          bool           | optional |    If true, other toasts will be dismissed. Default false.    |\n| movingOnWindowChange |          bool           | optional | If true, when the size changes, toast is moved. Default true. |\n|    textDirection     |      TextDirection      | optional |                                                               |\n|     textPadding      |   EdgeInsetsGeometry    | optional |                     Outer margin of text                      |\n|      textAlign       |        TextAlign        | optional |          When the text wraps, the align of the text.          |\n|     handleTouch      |          bool           | optional | Default is false, if it's true, can responed use touch event. |\n|   animationBuilder   | OKToastAnimationBuilder | optional |              Add animation to show / hide toast.              |\n|  animationDuration   |        Duration         | optional |                  The duration of animation.                   |\n|    animationCurve    |          Curve          | optional |                      Curve of animation.                      |\n|       duration       |        Duration         | optional |                  Default duration of toast.                   |\n\n### Method `showToast`\n\nDisplay text on toast.\n\nDescription of params see `OKToast`.\n\n|       name        |          type           |   need   |      desc      |\n|:-----------------:|:-----------------------:|:--------:|:--------------:|\n|        msg        |         String          | required | Text of toast. |\n|      context      |      BuildContext       | optional |                |\n|     duration      |        Duration         | optional |                |\n|     position      |      ToastPosition      | optional |                |\n|     textStyle     |        TextStyle        | optional |                |\n|    textPadding    |   EdgeInsetsGeometry    | optional |                |\n|  backgroundColor  |          Color          | optional |                |\n|      radius       |         double          | optional |                |\n|     onDismiss     |        Function         | optional |                |\n|   textDirection   |      TextDirection      | optional |                |\n| dismissOtherToast |          bool           | optional |                |\n|     textAlign     |        TextAlign        | optional |                |\n| animationBuilder  | OKToastAnimationBuilder | optional |                |\n| animationDuration |        Duration         | optional |                |\n|  animationCurve   |          Curve          | optional |                |\n\n### Method `showToastWidget`\n\nDisplay custom widgets on toast\n\nDescription of params see `showToast`.\n\n|       name        |          type           |   need   |              desc               |\n|:-----------------:|:-----------------------:|:--------:|:-------------------------------:|\n|      widget       |         Widget          | required | The widget you want to display. |\n|      context      |      BuildContext       | optional |                                 |\n|     duration      |        Duration         | optional |                                 |\n|     position      |      ToastPosition      | optional |                                 |\n|     onDismiss     |        Function         | optional |                                 |\n| dismissOtherToast |          bool           | optional |                                 |\n|   textDirection   |      TextDirection      | optional |                                 |\n|    handleTouch    |          bool           | optional |                                 |\n| animationBuilder  | OKToastAnimationBuilder | optional |                                 |\n| animationDuration |        Duration         | optional |                                 |\n|  animationCurve   |          Curve          | optional |                                 |\n\n### Method `dismissAllToast`\n\nDismiss all toast.\n\n### Return value of `showToast` and `showToastWidget`\n\nabout return type:  \n`showToast` and `showToastWidget` return type is `ToastFuture`,\nThe `ToastFuture` can be use to dismiss the toast.\n\n### For all dismiss toast method\n\nAn optional parameter `showAnim` is added to control whether fading animation is required for dismiss.\n\nThe praram default value is `false`.\n\n## Examples\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'package:oktoast/oktoast.dart'; // 1. import library\n\nvoid main() =\u003e runApp( MyApp());\n\nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return OKToast(\n      // 2. wrap your app with OKToast\n      child:  MaterialApp(\n        title: 'Flutter Demo',\n        theme:  ThemeData(\n          primarySwatch: Colors.blue,\n        ),\n        home:  MyHomePage(),\n      ),\n    );\n  }\n}\n\nclass MyHomePage extends StatefulWidget {\n  MyHomePage({Key key}) : super(key: key);\n\n  @override\n  _MyHomePageState createState() =\u003e  _MyHomePageState();\n}\n\nclass _MyHomePageState extends State\u003cMyHomePage\u003e {\n  int _counter = 0;\n\n  void _incrementCounter() {\n    _counter++;\n\n    // 3.1 use showToast method\n    showToast(\n      \"$_counter\",\n      duration: Duration(seconds: 2),\n      position: ToastPosition.bottom,\n      backgroundColor: Colors.black.withOpacity(0.8),\n      radius: 13.0,\n      textStyle: TextStyle(fontSize: 18.0),\n    );\n\n    showToast(\n      \"$_counter\",\n      duration: Duration(seconds: 2),\n      position: ToastPosition.top,\n      backgroundColor: Colors.black.withOpacity(0.8),\n      radius: 3.0,\n      textStyle: TextStyle(fontSize: 30.0),\n    );\n\n    // 3.2 use showToastWidget method to custom widget\n    Widget widget = Center(\n      child: ClipRRect(\n        borderRadius: BorderRadius.circular(30.0),\n        child: Container(\n          width: 40.0,\n          height: 40.0,\n           color: Colors.grey.withOpacity(0.3),\n          child: Icon(\n            Icons.add,\n            size: 30.0,\n            color: Colors.green,\n          ),\n        ),\n      ),\n    );\n\n    ToastFuture toastFuture = showToastWidget(\n      widget,\n      duration: Duration(seconds: 3),\n      onDismiss: () {\n        print(\"the toast dismiss\"); // the method will be called on toast dismiss.\n      },\n    );\n\n    // can use future\n    Future.delayed(Duration(seconds: 1), () {\n      toastFuture.dismiss(); // dismiss\n    });\n\n    setState(() {\n\n    });\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return  Scaffold(\n      appBar:  AppBar(\n        title:  Text(\"ktoast demo\"),\n      ),\n      body: Stack(\n        children: \u003cWidget\u003e[\n           Center(\n            child: ListView(\n              children: \u003cWidget\u003e[\n                 Text(\n                  'You have pushed the button this many times:',\n                ),\n                 Text(\n                  '$_counter',\n                  style: Theme.of(context).textTheme.display1,\n                ),\n                Padding(\n                  padding: const EdgeInsets.all(8.0),\n                  child: RaisedButton(\n                    onPressed: () {\n                      Navigator.push(context,\n                          MaterialPageRoute(builder: (ctx) =\u003e MyHomePage()));\n                    },\n                  ),\n                ),\n                Padding(\n                  padding: const EdgeInsets.all(8.0),\n                  child: RaisedButton(\n                    onPressed: _incrementCounter,\n                    child: Text('toast'),\n                  ),\n                ),\n              ],\n            ),\n          ),\n        ],\n      ),\n    );\n  }\n}\n\n\n```\n\n## CHANGELOG\n\n[Link](https://github.com/OpenFlutter/flutter_oktoast/blob/master/CHANGELOG.md)\n\n## LICENSE\n\n[Apache-2.0](https://github.com/OpenFlutter/flutter_oktoast/blob/master/LICENSE)\n","funding_links":[],"categories":["Dart","Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpenFlutter%2Fflutter_oktoast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOpenFlutter%2Fflutter_oktoast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpenFlutter%2Fflutter_oktoast/lists"}