How can i pass the data that i get from user via _textController and save it on a variable on the other class? I want to get the data that i get from the user and save it on a variable on the other class
final _textController = TextEditingController();
String userPost = "";
@override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
final double width = MediaQuery.of(context).size.width;
return ScreenUtilInit(
designSize: const Size(375, 812),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.amber,
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(95, 44, 130, 1),
Color.fromRGBO(73, 160, 157, 1),
])),
Padding(
padding: EdgeInsets.all(60.sp),
child: TextFormField(
controller: _textController,
decoration: InputDecoration(
labelText: 'What s your name?',
suffixIcon: IconButton(
onPressed: () {
_textController.clear();
},
icon: const Icon(Icons.clear))),
),
),
SizedBox(
height: 5.h,
),
MaterialButton(
elevation: 0,
onPressed: () {
setState(() {
userPost = _textController.text;
_textController.clear();
});
},
and displayed here :
showToast();
NotificationService().showNotification(
1,
'You can, ',
randomName!,
);
},
I don t know how to pass the data
2
Answers
I think u can use Riverpod StateProvider.
For using this
valueProvider
u must use ConsumerStatefulWidget instead of StatefulWidgetEditing
valueProvider
Using
valueProvider
from another ConsumerStatefulWidgetNOTE
I recommend you look State Management in Flutter topic I think it is critical part of Flutter Development.
u could simply call the showtoast() function in the onpressed() for any button and pass it the parameters which you want to use,
as
and change this
to