Install and Setup oktoast
mainTo use oktoast in your Flutter project, follow these steps:
Add the dependency to your
pubspec.yaml:flutter pub add oktoastImport the library in your Dart files:
import 'package:oktoast/oktoast.dart';Wrap your app widget with
OKToast. This ensures toasts are displayed in front of all other controls and allows the library to cache context so you can call toast methods anywhere without passing aBuildContext.
Important: Handling No MediaQuery widget found errors
If you encounter this error, wrap the MaterialApp builder instead of wrapping the MaterialApp itself:
MaterialApp(
builder: (BuildContext context, Widget? widget) {
return OKToast(child: widget);
},
);import 'package:oktoast/oktoast.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return OKToast(
child: MaterialApp(
home: MyHomePage(),
),
);
}
}