I have the following Flutter code, and I'm trying to figure out how to put section 1 into a separate class so that I can reuse it on multiple screens, and then separately (not at the same time, but instead of), how to put section 2 (which is a larger portion of code) into a separate class and how to reuse that on multiple pages with a variable to be able to change the title. Currently, I'm just copying and pasting the entire code into each screen, but I know there has to be a better way by reusing code.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
//------------------START SECTION 2---------------------------------------------
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text(
"Welcome",
style: TextStyle(color: Colors.white),
),
actions: <Widget>[
// action button
//------------------START SECTION 1---------------------------------------------
PopupMenuButton<String>(
//onSelected: showMenuSelection
//icon: new Icon(Icons.add, color: Colors.blueGrey),
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
const PopupMenuItem<String>(
value: 'Item 1', child: Text('Item 1')),
const PopupMenuItem<String>(
value: 'Item 2', child: Text('Item 2')),
],
),
//------------------END SECTION 1---------------------------------------------
],
),
//------------------END SECTION 2---------------------------------------------
body: Center(
child: Text('Hello World'),
),
),
);
}
}