Flutter 如何让一个抽屉有两种不同的颜色

Flutter 如何让一个抽屉有两种不同的颜色,flutter,flutter-layout,Flutter,Flutter Layout,我想弄清楚如何让绿色填充黄色标题下的整个抽屉空间。现在我将我的ListTiles包装在一个列中,在一个容器中,容器颜色设置为绿色。感谢所有的帮助 其中一种方法是将可能与绿色容器一起使用的ListView包装起来。请参阅下面的代码: import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widge

我想弄清楚如何让绿色填充黄色标题下的整个抽屉空间。现在我将我的ListTiles包装在一个列中,在一个容器中,容器颜色设置为绿色。感谢所有的帮助


其中一种方法是将可能与绿色容器一起使用的ListView包装起来。请参阅下面的代码:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: HomePage());
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Flutter Demo"),
      ),
      body: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        color: Colors.white,
      ),
      drawer: Container(
        color: Colors.green,
        child: ListView(
          children: <Widget>[
            DrawerHeader(
              padding: const EdgeInsets.all(0),
              child: Container(
                child: const Center(child: Text("Profile")),
                color: Colors.yellow,
              ),
            ),
            ListTile(
              title: const Text('Item 1'),
              tileColor: Colors.green,
              onTap: () {
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: const Text('Item 2'),
              tileColor: Colors.green,
              onTap: () {
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回资料app(主页:HomePage());
}
}
类主页扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:常量文本(“颤振演示”),
),
主体:容器(
高度:MediaQuery.of(context).size.height,
宽度:MediaQuery.of(context).size.width,
颜色:颜色,白色,
),
抽屉:集装箱(
颜色:颜色。绿色,
子:ListView(
儿童:[
抽屉阅读器(
填充:常量边集。全部(0),
子:容器(
子对象:常量中心(子对象:文本(“配置文件”),
颜色:颜色,黄色,
),
),
列表砖(
标题:常量文本(“项目1”),
tileColor:Colors.green,
onTap:(){
Navigator.pop(上下文);
},
),
列表砖(
标题:常量文本(“项目2”),
tileColor:Colors.green,
onTap:(){
Navigator.pop(上下文);
},
),
],
),
),
);
}
}

请分享您的代码,以更好地帮助您,谢谢。非常感谢您,实际上比这更简单。我所要做的只是“drawer:Container()”而不是“drawer:drawer()”。你是对的,我根据你的评论修复了代码和描述。