【发布时间】:2021-12-30 00:23:39
【问题描述】:
我创建了一个抽屉,它工作正常,但不知道如何使用DrawerHeader 显示一半背景。就像我附加的图片一样,个人资料图片周围也有圆形。当我涂上颜色时,它需要一个完整的抽屉。这是我到目前为止尝试过的代码。
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const appTitle = 'Drawer Demo';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: appTitle,
home: MyHomePage(title: appTitle),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: const Center(
child: Text('My Page!'),
),
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('Drawer Header'),
),
ListTile(
title: const Text('Item 1'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
ListTile(
title: const Text('Item 2'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
],
),
),
);
}
}
【问题讨论】:
-
这是一个问答网站...不是教程论坛...描述您尝试过的内容...包括任何代码和错误消息...还可以提出一个具体的、可回答的问题
-
是的,现在我添加了我的代码和图像,如下所示只是我需要i.stack.imgur.com/0VLdY.png
标签: flutter user-interface flutter-layout drawer