如何实现填满屏幕的盒子,我看不到我的抽屉

问题描述 投票:0回答:2

我正在尝试实现UI设计,如下所示:

enter image description here

这就是我迄今取得的成就:

enter image description here

我陷入了用盒子填充屏幕的阶段,我尝试以多种方式实现这一点(扩展,容器等),但结果并不能让我满意。我该如何实现?

而且我还有另一个问题,当我创建它工作的抽屉(我可以向右滚动屏幕并出现抽屉导航屏幕),但我看不到抽屉图标。

顺便说一下,如果你有改进代码的建议或我可以写得更好的东西,我会很高兴听到这个

我的代码:

 class Sample extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
      drawer: Drawer(),
body: Column(
            children: <Widget>[
              Stack(
                children: <Widget>[
                  Container(
                    height: MediaQuery.of(context).size.height / 2,
                    width: double.infinity,
                    color: Color.fromRGBO(50, 50, 205, 1),
                  ),
                  Opacity(
                    child: Image.network(
                      'https://cdn.pixabay.com/photo/2015/04/23/21/36/auto-736794__340.jpg',
                      //half of the screen
                      height: MediaQuery.of(context).size.height / 2,
                      fit: BoxFit.cover,
                    ),
                    opacity: 0.3,
                  ),
                  SafeArea(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Padding(
                          padding: const EdgeInsets.only(bottom: 58.0),
                          child: Text(
                            'Parking App',
                            style: TextStyle(color: Colors.white, fontSize: 20.0),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),

            ],
          ),
        );
      }
    }
dart flutter flutter-layout
2个回答
0
投票

可能有更好的方法来实现这一点,但这里是行和列的解决方案:

import 'package:flutter/material.dart';

class SamplePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final screenHeight = MediaQuery.of(context).size.height;
    return Scaffold(
      body: Column(
        children: <Widget>[
          Image.network(
            "http://i63.tinypic.com/16p2xu.jpg",
            fit: BoxFit.cover,
            height: screenHeight / 2,
          ),
          Expanded(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Column(
                    children: <Widget>[
                      Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Icon(Icons.account_balance),
                            SizedBox(height: 10),
                            Text("My Stats"),
                          ],
                        ),
                      ),
                      Expanded(
                        child: Container(
                          color: Colors.indigo,
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.stretch,
                            children: <Widget>[
                              Icon(Icons.accessibility, color: Colors.white),
                              SizedBox(height: 10),
                              Center(
                                child: Text(
                                  "Component",
                                  style: TextStyle(color: Colors.white),
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Container(
                    color: Colors.cyanAccent,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Icon(Icons.access_alarm),
                        SizedBox(height: 20),
                        Text("Workout"),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

结果:

enter image description here


0
投票

你可以使用堆栈实现类似的布局。我演示如下。

注意:确保您使用全屏内容,否则将出现黑屏。

class Sample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Column(
          children: <Widget>[
            Container(
              height: MediaQuery.of(context).size.height / 2,
              width: double.infinity,
              decoration: BoxDecoration(
                color: Color.fromRGBO(50, 50, 205, 0.3),
                image: DecorationImage(
                  image: NetworkImage(
                    'https://cdn.pixabay.com/photo/2015/04/23/21/36/auto-736794__340.jpg',
                  ),
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ],
        ),
        Scaffold(
          backgroundColor: Colors.transparent,
          drawer: Drawer(),
          appBar: AppBar(
            backgroundColor: Colors.transparent,
            elevation: 0.0,
            title: new Text("Demo"),
            centerTitle: true,
          ),
          body: Column(
            children: <Widget>[
              Expanded(
                child: Center(
                  child: new Container(
                    decoration: BoxDecoration(
                      color: Colors.red
                    ),
                    child: new Text("book"),
                  ),
                ),
              )
            ],
          ),
        ),
      ],
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.