导入'包:flutter/material.dart'; 导入'包:hlibrary/main.dart';
类面板扩展StatelessWidget { const Panel({Key? key});
@覆盖 小部件构建(BuildContext 上下文){
return Stack(
children: [
Scaffold(
appBar: AppBar(
centerTitle: false,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Hlibrary",
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Colors.orangeAccent,
),),
Text("Admin Panel",
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Colors.orangeAccent,
),),
],)
),
floatingActionButton: FloatingActionButton(
onPressed: (){},
backgroundColor: Colors.orangeAccent,
child: const Icon(Icons.add),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
const DrawerHeader(
decoration: BoxDecoration(
color: Color(0xFFFFB800),
),
child: Text(
'Admin Tengis',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
ListTile(
leading: Icon(Icons.add),
title: const Text('Add'),
onTap: () {
// Handle Option 1
},
),
ListTile(
leading: Icon(Icons.list),
title: const Text('Added files'),
onTap: () {
// Handle Option 2
},
),
ListTile(
leading: Icon(Icons.arrow_back),
title: const Text('Go back'),
onTap: () {
Navigator.pop(context);
},
),
// Add more ListTile for additional options
],
),
),
body: ListView(
),
),
],
);
} }
您可以这样处理,只需创建一个列表来存储选定的类别并显示该列表即可。
无论这些类别在哪里,都显示在抽屉中甚至正文中。
class HomeScreen extends StatefulWidget{
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<String> catgs = [];
@override
Widget build(BuildContext context){
return Scaffold(
body: Column(
children: [
ListTile(
title: Text('Science'),
onTap: (){
setState((){
catgs.add('Science');
});
},
),
ListTile(
title: Text('Sports'),
onTap: (){
setState((){
catgs.add('Sports');
});
},
),
if(catgs.isNotEmpty)
Expanded(
child: ListView(
children: catgs.map((e)=> ListTile(title: Text(e),)).toList(),
),
)
],
)
);
}
}
弄清楚这个想法是如何运作的,然后应用它。