//appBar的 leading/actions 和 Scaffold的drawer/endDrawer 冲突只能存在一个
import 'package:flutter/material.dart';void main() {runApp(MyApp());
}class MyApp extends StatelessWidget {const MyApp({super.key});@overrideWidget build(BuildContext context) {return const MaterialApp(title: 'contaniner', home: HomePage());}
}class HomePage extends StatefulWidget {const HomePage({super.key});@overrideState<HomePage> createState() => _HomePageState();
}class _HomePageState extends State<HomePage> {final _leftList = List.generate(20,(index) => const Column(children: [ListTile(leading: CircleAvatar(child: Icon(Icons.swipe_left, size: 30)),title: Text('左侧数据'),trailing: Icon(Icons.keyboard_arrow_right),),Divider()],),);final _rightList = List.generate(20,(index) => const Column(children: [ListTile(leading: CircleAvatar(child: Icon(Icons.swipe_right, size: 30)),title: Text('右侧数据'),selectedColor: Colors.green,trailing: Icon(Icons.keyboard_arrow_right),),Divider()],),);@overrideWidget build(BuildContext context) {return Scaffold(drawer: Drawer(child: Column(children: [Container(width: double.infinity,child: const DrawerHeader(decoration: BoxDecoration(color: Colors.pink),child: Text("左侧侧数据"),),),Expanded(child: ListView(children: [..._leftList],),),],),),endDrawer: Drawer(child: Column(children: [Container(width: double.infinity,child: const DrawerHeader(decoration: BoxDecoration(color: Colors.green),child: Text("左侧侧数据"),),),Expanded(child: ListView(children: [..._rightList],),),],),),appBar: AppBar(title: const Center(child: Text('flutter bar')),// leading: IconButton(// onPressed: () => print("我是图标按钮1"),// icon: Icon(Icons.ac_unit), //设置图标// color: Colors.red, //设置按钮颜色// splashColor: Colors.yellow, //设置水波纹// highlightColor: Colors.purple, //设置高亮的颜色// tooltip: '我是提示信息', //提示信息// ),// actions: const [// Icon(Icons.settings),// Icon(Icons.vaccines),// ],backgroundColor: Colors.cyan[800],elevation: 0.0,centerTitle: true,),//带索引的集合循环body:HomeWidget());}
}class HomeWidget extends StatelessWidget {const HomeWidget({super.key});@overrideWidget build(BuildContext context) {// return const Text('我是首页数据', style: TextStyle(color: Colors.red));return ListView(children: List.generate(20,(index) => ListTile(leading: Icon(Icons.access_alarm, size: 30),title: Text('测试$index'),subtitle: Text('子标题$index'),selected: index == 1,selectedColor: Colors.green,trailing: Icon(Icons.keyboard_arrow_right),),));}
}