What is the cause of this problem? When I click on the button to show the toast, this message appears
The following _CastError was thrown while handling a gesture: Null check operator used on a null value
*When the exception was thrown, this was the stack: showToastWidget (package:flutter_styled_toast/src/styled_toast.dart:268:22)
home: Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
showToast(txt,
context: context,
animation: StyledToastAnimation.slideFromLeft,
reverseAnimation: StyledToastAnimation.slideToBottom,
position: StyledToastPosition(
align: Alignment.bottomCenter, offset: 55),
animDuration: Duration(milliseconds: 300),
duration: Duration(seconds: 2),
curve: Curves.easeInOutBack,
reverseCurve: Curves.elasticIn,
backgroundColor: Color.fromRGBO(191, 21, 35, 0.5),
textStyle: TextStyle(fontSize: 20, color: Colors.white));
},
child: const Icon(Icons.add),
),
appBar: AppBar(title: Text('Flutter Code Sample')),
body: const Center(
child: MyStatelessWidget(),
),
),
);
}
}
Answer:
import 'package:flutter/material.dart';
import 'dialogPage.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home:DialogPage() ,
);
}
}
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
showToast(txt,
context: context,
animation: StyledToastAnimation.slideFromLeft,
reverseAnimation: StyledToastAnimation.slideToBottom,
position: const StyledToastPosition(
align: Alignment.bottomCenter, offset: 55),
animDuration: Duration(milliseconds: 300),
duration: const Duration(seconds: 2),
curve: Curves.easeInOutBack,
reverseCurve: Curves.elasticIn,
backgroundColor: Color.fromRGBO(191, 21, 35, 0.5),
textStyle: TextStyle(fontSize: 20, color: Colors.white));
},
child: const Icon(Icons.add),
),
appBar: AppBar(title: Text('Flutter Code Sample')),
body: const Center(
child: MyStatelessWidget(),
),
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.