I want to transfer the data from text field in floatingActionButton witch is thefloatingactionbutton in MainWidget to MainWidget class in to the text
kind of want to give and get the data from these two class
void main() async {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: MainWidget(),
);
}
}
// MainWidget class
class MainWidget extends StatefulWidget {
const MainWidget({super.key});
@override
State<MainWidget> createState() => _MainWidgetState();
}
class _MainWidgetState extends State<MainWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
// I want to get it from here
child: Text(),
),
),
floatingActionButton: floatingActionButton(),
);
}
}
// the floatingActionButton class
class floatingActionButton extends StatefulWidget {
const floatingActionButton({super.key});
@override
State<floatingActionButton> createState() => _floatingActionButtonState();
}
class _floatingActionButtonState extends State<floatingActionButton> {
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
content: Center(
child: Container(
child: Column(
children: [
I want to send data from here
TextField(),
IconButton(onPressed: () {}, icon: Icon(Icons.send))
],
),
)),
);
},
);
},
);
},
);
}
}
I tried the constructor
but I cant becouse I use the class in here :
void main() async {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: MainWidget(),
);
}
}
I want to send and get the data without constructor