如下圖所示,我必須在我的應用程式的某些路徑中顯示側邊選單,為此我使用下面的代碼,如下圖所示,此選單是作為抽屜打開的,但是當它打開時顯示在頂部有一個白色部分仍然可見。如何確保它不顯示?
應用程式圖片
飛鏢代碼:
class SideMenuWidget extends StatelessWidget {
final padding = EdgeInsets.symmetric(horizontal: 20);
final nome, cognome, email;
SideMenuWidget(this.nome, this.cognome, this.email);
@override
Widget build(BuildContext context) {
final name = '' nome ' ' cognome;
return Material(
color: Colors.white,
child: ListView(
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
children: <Widget>[
buildHeader(
name: name,
email: email,
onClicked: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => LoginPage(),
)),
),
Container(
padding: padding,
child: Column(
children: [
const SizedBox(height: 12),
buildMenuItem(
text: 'DashBoard',
icon: Icons.dashboard,
onClicked: () => selectedItem(context, 0),
),
const SizedBox(height: 16),
buildMenuItem(
text: 'Libreria',
icon: Icons.book,
onClicked: () => selectedItem(context, 1),
),
const SizedBox(height: 16),
buildMenuItem(
text: 'I miei libri',
icon: Icons.workspaces_outline,
onClicked: () => selectedItem(context, 2),
),
const SizedBox(height: 16),
buildMenuItem(
text: 'Marketplace',
icon: Icons.book,
onClicked: () => selectedItem(context, 3),
),
//Divider(color: Colors.white70),
const SizedBox(height: 16),
buildMenuItem(
text: 'Messaggi',
icon: Icons.message,
onClicked: () => selectedItem(context, 4),
),
const SizedBox(height: 16),
buildMenuItem(
text: 'Profilo',
icon: Icons.supervised_user_circle_rounded,
onClicked: () => selectedItem(context, 5),
),
const SizedBox(height: 100),
],
),
),
],
),
);
}
Widget buildHeader({
required String name,
required String email,
required VoidCallback onClicked,
}) =>
InkWell(
onTap: onClicked,
child: Container(
color: '#448BB5'.toColor(),
padding: padding.add(EdgeInsets.symmetric(vertical: 40)),
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(fontSize: 20, color: Colors.white),
),
const SizedBox(height: 4),
Text(
email,
style: TextStyle(fontSize: 14, color: Colors.white),
),
],
),
],
),
),
);
Widget buildMenuItem({
required String text,
required IconData icon,
VoidCallback? onClicked,
}) {
final hoverColor = Colors.white70;
return ListTile(
leading: Icon(icon, color: '#448BB5'.toColor()),
title: Text(text, style: TextStyle(color: "#448BB5".toColor())),
hoverColor: hoverColor,
onTap: onClicked,
);
}
void selectedItem(BuildContext context, int index) {
Navigator.of(context).pop();
switch (index) {
case 0:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => DashBoardPage(),
));
break;
case 1:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => LibrerieHomeView(),
));
break;
case 2:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => LibrerieHomeView(),
));
break;
case 4:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => MessagePage(),
));
break;
case 3:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => MarketPlacePage(),
));
break;
case 5:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ProfiloPage(),
));
break;
}
}
}
uj5u.com熱心網友回復:
用 包裹你Scaffold()的SafeArea()。使用此 flutter 將知道您不想將小部件與移動設備的狀態欄重疊。
return SafeArea(
child: Scaffold(
drawer: YourDrawer(),
body:YourPage(),
),
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/367002.html
上一篇:身份驗證狀態更改回傳始終為空
