簡體   English   中英

顫振如何使AppBar的條形傾斜物垂直居中?

[英]Flutter How to vertically center the AppBar sliver tilte?

我試圖將Sliver AppBar的標題居中,並在此下方添加第二個文本。 我做不到。

下面是現在的圖像以及應該如何顯示。

誰能幫我?

這是我的代碼。

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小部件:

    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: () {/* ... */},
                    ),
                  ],
                ),
              ],
            )); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM