Flutter 颤振堆栈布局容器使用剩余高度

Flutter 颤振堆栈布局容器使用剩余高度,flutter,flutter-layout,Flutter,Flutter Layout,我从颤振开始 我正在构建一个布局,看起来像 我正在使用Stack构建这个布局,其中背景色中的部分是另一个Stack子级,父级容器高度为固定值 到目前为止我写的代码是 import 'dart:math'; import 'package:flutter/material.dart'; import 'package:whatsappwithoutcontact/components/form_fields.dart'; import 'package:whatsappwithoutconta

我从颤振开始

我正在构建一个布局,看起来像

我正在使用Stack构建这个布局,其中背景色中的部分是另一个Stack子级,父级容器高度为固定值

到目前为止我写的代码是

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:whatsappwithoutcontact/components/form_fields.dart';
import 'package:whatsappwithoutcontact/screens/info/info-screen.dart';


class MessageScreen extends StatefulWidget {
  @override
  _MessageScreenState createState() => _MessageScreenState();
}

class _MessageScreenState extends State<MessageScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('WhatsApp without Contact'),
        backgroundColor: Colors.transparent,
        elevation: 0.0,
        actions: [
          IconButton(
            icon: Icon(Icons.info),
            onPressed: _onInfoPressed,
          )
        ],
      ),
      extendBodyBehindAppBar: true,
      body: MessageContainer()
    );
  }

  void _onInfoPressed() {
    Navigator.of(context).push(
      MaterialPageRoute<void> (
        builder: (BuildContext context) {
          return InfoScreen();
        }
      )
    );
  }
}

class MessageContainer extends StatefulWidget {
  @override
  _MessageContainerState createState() => _MessageContainerState();
}

class _MessageContainerState extends State<MessageContainer> {
  static const double avatarRadius = 35;
  static const double titleBottomMargin = (avatarRadius * 2) + 18;
  static const double _headerHeight = 350.0;
  final _formKey = GlobalKey<FormState>();
  final _messageFieldFocusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    return Form(
      key: _formKey,
      child: Stack(
        children: [
          Container(
            height: _headerHeight,
            child: Stack(
              children: <Widget>[
                Container(
                  child: ClipPath(
                    clipper: HeaderClipper(avatarRadius: avatarRadius),
                    child: CustomPaint(
                      size: Size(MediaQuery.of(context).size.width, _headerHeight),
                      painter: HeaderPainter(
                          color: Colors.green,
                          avatarRadius: avatarRadius
                      ),
                    ),
                  ),
                ),
                Positioned(
                  left: 0,
                  right: 0,
                  child: Container(
                    padding: EdgeInsets.only(top: 80.0),
                    margin: EdgeInsets.all(50.0),
                    child: Column(
                      children: <Widget>[
                        FormTextField(
                          labelText: 'Country Code',
                          validator: (value) {
                            if (value.isEmpty) {
                              return 'Required';
                            }
                            return null;
                          }
                        ),
                        SizedBox(height: 15.0,),
                        FormTextField(
                          labelText: 'Phone Number',
                          validator: (value) {
                            if (value.isEmpty) {
                              return 'Required';
                            }
                            return null;
                          },
                        )
                      ],
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.bottomCenter,
                  child: CircleAvatar(
                    radius: avatarRadius,
                    backgroundColor: Colors.green,
                    child: IconButton(icon: Icon(Icons.message), onPressed: _onAddMessageButtonClick,),
                  ),
                )
              ],
            ),
          ),
          SingleChildScrollView(
            child: Padding(
              padding: EdgeInsets.symmetric(
                vertical: _headerHeight,
                horizontal: 50
              ),
              child: Column(
                children: [
                    TextFormField(
                      keyboardType: TextInputType.multiline,
                      maxLines: 4,
                      focusNode: _messageFieldFocusNode,
                      decoration: InputDecoration(
                        labelText: 'Message',
                        fillColor: Colors.white,
                        labelStyle: TextStyle(
                          color: _messageFieldFocusNode.hasFocus ? Colors.green : Colors.grey
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.grey
                          )
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.green
                          )
                        )
                      ),
                    )
                ],
              ),
            ),
          ),
        ],
      )
    );

  }
}
import'dart:math';
进口“包装:颤振/材料.省道”;
导入“package:whatsappwithoutcontact/components/form_fields.dart”;
导入“package:whatsappwithoutcontact/screens/info/info screen.dart”;
类MessageScreen扩展了StatefulWidget{
@凌驾
_MessageScreenState createState()=>\u MessageScreenState();
}
类_MessageScreenState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“WhatsApp无触点”),
背景颜色:颜色。透明,
标高:0.0,
行动:[
图标按钮(
图标:图标(Icons.info),
onPressed:\u onInfoPressed,
)
],
),
extendedBodyBehindAppBar:true,
正文:MessageContainer()
);
}
void _onInfoPressed(){
导航器.of(上下文).push(
材料路线(
生成器:(BuildContext上下文){
返回InfoScreen();
}
)
);
}
}
类MessageContainer扩展StatefulWidget{
@凌驾
_MessageContainerState createState();
}
类_MessageContainerState扩展状态{
静态常数双阿瓦塔拉迪乌斯=35;
静态常数双标题BottleBottommargin=(阿瓦塔拉迪乌斯*2)+18;
静态常数双U形头锤=350.0;
final _formKey=GlobalKey();
final _messageFieldFocusNode=FocusNode();
@凌驾
小部件构建(构建上下文){
报税表(
键:_formKey,
子:堆栈(
儿童:[
容器(
高度:(U头八),
子:堆栈(
儿童:[
容器(
孩子:克利帕斯(
克利伯:头号捕快(阿瓦塔拉迪乌斯:阿瓦塔拉迪乌斯),
孩子:定制油漆(
size:size(MediaQuery.of(context.size.width,_headerHeight),
画家:头画(
颜色:颜色。绿色,
阿瓦塔拉迪乌斯:阿瓦塔拉迪乌斯
),
),
),
),
定位(
左:0,,
右:0,,
子:容器(
填充:仅限边缘设置(顶部:80.0),
保证金:所有边缘套(50.0),
子:列(
儿童:[
FormTextField(
labelText:“国家代码”,
验证器:(值){
if(value.isEmpty){
返回“必需”;
}
返回null;
}
),
尺寸箱(高度:15.0,),
FormTextField(
labelText:'电话号码',
验证器:(值){
if(value.isEmpty){
返回“必需”;
}
返回null;
},
)
],
),
),
),
对齐(
对齐:对齐.bottomCenter,
孩子:圆环星(
半径:阿瓦塔拉迪乌斯,
背景颜色:Colors.green,
子项:图标按钮(图标:图标(Icons.message),ON按下:_onaddmessage按钮单击,),
),
)
],
),
),
SingleChildScrollView(
孩子:填充(
填充:EdgeInsets.symmetric(
垂直方向:_headerHeight,
横向:50
),
子:列(
儿童:[
TextFormField(
键盘类型:TextInputType.multiline,
maxLines:4,
focusNode:_messageFieldFocusNode,
装饰:输入装饰(
labelText:'消息',
fillColor:Colors.white,
标签样式:文本样式(
颜色:_messageFieldFocusNode.hasFocus?颜色。绿色:颜色。灰色
),
enabledBorder:OutlineInputBorder(
边界边(
颜色:颜色。灰色
)
),
聚焦顺序:大纲输入边框(
边界边(
颜色:颜色。绿色
)
)
),
)
],
),
),
),
],
)
);
}
}
第一个堆栈中的第一个容器是绿色背景部分,SingleChildScrollView是绿色背景下的部分

SingleChildScrollView正在使下部可滚动,而我希望它是固定的,并占用中央
消息
图标下方的剩余空间

我尝试使用容器,但是没有显示
消息
输入字段

  • 如何使用堆栈布局下方的剩余空间?