颤振如何使AppBar细条倾斜垂直居中? [英] Flutter How to vertically center the AppBar sliver tilte?

查看:125
本文介绍了颤振如何使AppBar细条倾斜垂直居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Sliver AppBar的标题居中,并在此下方添加第二个文本.我做不到.

I'm trying to center the title of Sliver AppBar and add a second text below this. I can not do it.

下面是现在的图像以及应该如何显示.

Below is the image that is now and how it should be.

有人可以帮助我吗?

这是我的代码.

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Slive AppBar',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      debugShowCheckedModeBanner: false,
      home: new MyHomePage(title: 'Slive AppBar'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        drawer: new Drawer(),
        body: new CustomScrollView(
          scrollDirection: Axis.vertical,
          slivers: <Widget>[
            new SliverAppBar(
              expandedHeight: 150.0,
              flexibleSpace: const FlexibleSpaceBar(
                title: const Text("US\$ 123.456.78"),
                centerTitle: true,
              ),
              backgroundColor: Colors.redAccent,
              pinned: true,
              actions: <Widget>[
                new IconButton(
                  icon: const Icon(Icons.add_circle),
                  tooltip: 'Balance',
                  onPressed: () {/* ... */},
                ),
              ],
            ),
          ],
        ));
  }
}

" " " """ " """"" " " """"""""""""""

"" "" "" """""" "" """""""""" "" "" """"""""""""""""""""""""""""

推荐答案

您可以使用所需的children创建Column小部件:

You can create a Column widget with the children that you need:

    return new Scaffold(
            drawer: new Drawer(),
            body: new CustomScrollView(
              scrollDirection: Axis.vertical,
              slivers: <Widget>[
                new SliverAppBar(
                  expandedHeight: 140.0,
                  flexibleSpace:  FlexibleSpaceBar(
                    title:  Column(
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                        mainAxisAlignment: MainAxisAlignment.start,
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          const Text("US\$ 123.456.78", textAlign: TextAlign.center,),
                          const Text("Anything", style: TextStyle(fontSize: 12.0),textAlign: TextAlign.center,),
                        ],
                      ),
                    centerTitle: true,
                  ),
                  backgroundColor: Colors.redAccent,
                  pinned: true,
                  actions: <Widget>[
                    new IconButton(
                      icon: const Icon(Icons.add_circle),
                      tooltip: 'Balance',
                      onPressed: () {/* ... */},
                    ),
                  ],
                ),
              ],
            )); 

这篇关于颤振如何使AppBar细条倾斜垂直居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆