I am building a podcasting type app, so need to call the record, stop, and play functions in many places, I created the methods, but difficulty to call these methods in other places.
main.dart
class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { String statusText = ""; bool isComplete = false; void startRecord() //Need to call all of these method in coming stateful widgets void stopRecord() // void pauseRecord()// void resumeRecord()// void play() // @override Widget build(BuildContext context) { return MaterialApp( home: Builder( builder: (context) => Scaffold( drawer: Drawer( elevation: 2.0, child: ListView( children: <Widget>[ ListTile( title: Text('Home'), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) { return MyApp(); }, ), ); }, ), //more code is here Expanded( child: GestureDetector( child: IconButton( icon: Icon(Icons.mic), color: Colors.white, iconSize: 40, onPressed: () async { startRecord(); }), ), ), } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return MaterialApp( onPressed: () { startRecord() // need to call the method here. } Pressed: () { stopRecord() // need to call the method here. } Pressed: () { play() // need to call the method here. } ), } Need to call all the methods from a first stateful widget for bottom stateful widgets
also, need to call these methods for other classes when code progress
both stateful widgets are in the main.dart. I could not call the method from the first class for the second stateful widget
startRecordoutside the_MyAppStateClass? and is the classes on differentDartfiles? And Can you share the whole code?