FlutterToast
1.0.0
フラッター用のトーストライブラリ
このトーストライブラリは、 BuildContextなしで他のBuildContext必要とする2種類のトーストメッセージをサポートしています
サポートされているプラットフォーム
- アンドロイド
- iOS
- web(Toistify-jsを使用)
これは限られた機能を持ち、UIを制御できません
サポートされているプラットフォーム
- 全て
# add this line to your dependencies
fluttertoast : ^8.2.10 import 'package:fluttertoast/fluttertoast.dart' ; Fluttertoast . showToast (
msg : "This is Center Short Toast" ,
toastLength : Toast . LENGTH_SHORT ,
gravity : ToastGravity . CENTER ,
timeInSecForIosWeb : 1 ,
backgroundColor : Colors .red,
textColor : Colors .white,
fontSize : 16.0
);| 財産 | 説明 | デフォルト |
|---|---|---|
| MSG | 文字列(nullではない)(必須) | 必須 |
| トーストレング | toast.length_shortまたはtoast.length_long(オプション) | toast.length_short |
| 重力 | toastgravity.top(or)toastgravity.center(or)toastgravity.bottom(webはトップ、ボトムのみをサポートしています) | Toastgravity.bottom |
| Timeinsecforiosweb | int(ios&web用) | 1(秒) |
| BackgroundColor | colors.red | ヌル |
| TextColor | colors.white | ヌル |
| fontsize | 16.0(フロート) | ヌル |
| fontasset | Flutter App Assetsフォルダーのフォントファイルへのパス、例: 'Assets/Path/to/some-font.ttf'(string) | ヌル |
| webshowclose | false(bool) | 間違い |
| webbgcolor | 文字列(六角色) | 線形勾配(右、#00B09B、#96C93D) |
| ウェブポジション | 文字列( left 、 center 、またはright ) | 右 |
Fluttertoast . cancel ()カスタムトーストはAndroid 11以降では機能しません。MSGのみを使用し、残りのすべてのプロパティは無視されます
プロジェクトapp/res/layoutフォルダーでtoast_custom.xmlという名前のファイルを作成し、カスタムスタイリングを実行します
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< FrameLayout xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : tools = " http://schemas.android.com/tools "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_gravity = " center_horizontal "
android : layout_marginStart = " 50dp "
android : background = " @drawable/corner "
android : layout_marginEnd = " 50dp " >
< TextView
android : id = " @+id/text "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : background = " #CC000000 "
android : paddingStart = " 16dp "
android : paddingTop = " 10dp "
android : paddingEnd = " 16dp "
android : paddingBottom = " 10dp "
android : textStyle = " bold "
android : textColor = " #FFFFFF "
tools : text = " Toast should be short. " />
</ FrameLayout >コンテキストの使用のために以下のようにbuilderであなたのMaterialAppを更新しますグローバルにドキュメントセクションをチェック
MaterialApp (
builder : FToastBuilder (),
home : MyApp (),
navigatorKey : navigatorKey,
), FToast fToast;
@override
void initState () {
super . initState ();
fToast = FToast ();
// if you want to use context from globally instead of content we need to pass navigatorKey.currentContext!
fToast. init (context);
}
_showToast () {
Widget toast = Container (
padding : const EdgeInsets . symmetric (horizontal : 24.0 , vertical : 12.0 ),
decoration : BoxDecoration (
borderRadius : BorderRadius . circular ( 25.0 ),
color : Colors .greenAccent,
),
child : Row (
mainAxisSize : MainAxisSize .min,
children : [
Icon ( Icons .check),
SizedBox (
width : 12.0 ,
),
Text ( "This is a Custom Toast" ),
],
),
);
fToast. showToast (
child : toast,
gravity : ToastGravity . BOTTOM ,
toastDuration : Duration (seconds : 2 ),
);
// Custom Toast Position
fToast. showToast (
child : toast,
toastDuration : Duration (seconds : 2 ),
positionedToastBuilder : (context, child) {
return Positioned (
child : child,
top : 16.0 ,
left : 16.0 ,
);
});
}
今、 _showToast()に電話してください
詳細については、プロジェクトexampleを確認してください
| 財産 | 説明 | デフォルト |
|---|---|---|
| 子供 | ウィジェット(nullではない)(必須) | 必須 |
| トーストデュレーション | 期間(オプション) | |
| 重力 | トーストグラビティ。* | |
| 配置されている | 配置されている | |
| フェードレッド | 間隔 | 期間(ミリ秒:350) |
| IngrorePointer | ブール | 間違い |
| isdisisible | ブール | 間違い |
コンテキストにnavigatorkeyを使用するには、最初にGlobalKey<NavigatorState> main.dartファイルの上位レベルで定義します。
GlobalKey < NavigatorState > navigatorKey = GlobalKey < NavigatorState >(); FToastの初期化の時点で、グローバルに定義されたGlobalKey<NavigatorState>のコンテキストを使用する必要があります
FToast fToast = FToast ();
fToast. init (yourNavKey.currentContext ! ); // To remove present shwoing toast
fToast. removeCustomToast ()
// To clear the queue
fToast. removeQueuedCustomToasts ();...