@@ -48,7 +48,6 @@ class _MyHomePageState extends State<MyHomePage> {
4848
4949 void _incrementCounter () {
5050 _counter++ ;
51-
5251 setState (() {});
5352 }
5453
@@ -103,66 +102,72 @@ class _MyHomePageState extends State<MyHomePage> {
103102 });
104103 }
105104
105+ ToastFuture ? _persistToast;
106+
107+ void _showPersistToast () {
108+ _persistToast = showToastWidget (
109+ Center (
110+ child: ElevatedButton (
111+ onPressed: () => _persistToast? .dismiss (),
112+ child: const Text ('Click this button to dismiss' ),
113+ ),
114+ ),
115+ duration: Duration .zero,
116+ handleTouch: true ,
117+ );
118+ }
119+
106120 @override
107121 Widget build (BuildContext context) {
108122 return Scaffold (
109123 appBar: AppBar (title: const Text ('Example for OKToast' )),
110- body: Stack (
111- children: < Widget > [
112- Center (
113- child: ListView (
114- children: < Widget > [
115- const Text ('You have pushed the button this many times:' ),
116- Text (
117- '$_counter ' ,
118- style: Theme .of (context).textTheme.headline4,
119- ),
120- Padding (
121- padding: const EdgeInsets .all (8.0 ),
122- child: Tooltip (
123- message: 'Toast status when using this to test routing.' ,
124- child: ElevatedButton (
125- child: const Text ('New page' ),
126- onPressed: () {
127- Navigator .push (
128- context,
129- MaterialPageRoute <void >(
130- builder: (_) => const MyHomePage (),
131- ),
132- );
133- },
134- ),
135- ),
136- ),
137- Padding (
138- padding: const EdgeInsets .all (8.0 ),
139- child: Tooltip (
140- message: 'Add number.' ,
141- child: ElevatedButton (
142- onPressed: _incrementCounter,
143- child: const Text ('Add' ),
144- ),
145- ),
146- ),
147- Padding (
148- padding: const EdgeInsets .all (8.0 ),
149- child: Tooltip (
150- message: 'Show toast.' ,
151- child: ElevatedButton (
152- onPressed: _showToast,
153- child: const Text ('Toast' ),
154- ),
155- ),
156- ),
157- const TextField (
158- decoration: InputDecoration (
159- hintText: 'Use TextField to test the toast of soft keys.' ,
160- ),
161- ),
162- ],
124+ body: Center (
125+ child: Column (
126+ mainAxisAlignment: MainAxisAlignment .center,
127+ children: < Widget > [
128+ const Center (
129+ child: Text ('You have pushed the button this many times:' ),
163130 ),
164- ),
165- ],
131+ Center (
132+ child: Text (
133+ '$_counter ' ,
134+ style: Theme .of (context).textTheme.headline4,
135+ ),
136+ ),
137+ Padding (
138+ padding: const EdgeInsets .all (8.0 ),
139+ child: ElevatedButton (
140+ onPressed: _showToast,
141+ child: const Text ('Show toast' ),
142+ ),
143+ ),
144+ Padding (
145+ padding: const EdgeInsets .all (8.0 ),
146+ child: ElevatedButton (
147+ onPressed: _showPersistToast,
148+ child: const Text ('Show a persist toast' ),
149+ ),
150+ ),
151+ Padding (
152+ padding: const EdgeInsets .all (8.0 ),
153+ child: ElevatedButton (
154+ child: const Text ('Toast during pushing to a new page' ),
155+ onPressed: () {
156+ _showToast ();
157+ Navigator .push (
158+ context,
159+ MaterialPageRoute <void >(builder: (_) => const MyHomePage ()),
160+ );
161+ },
162+ ),
163+ ),
164+ ],
165+ ),
166+ ),
167+ floatingActionButton: FloatingActionButton (
168+ onPressed: _incrementCounter,
169+ child: const Icon (Icons .add),
170+ tooltip: 'Add number' ,
166171 ),
167172 );
168173 }
0 commit comments