gpt4 book ai didi

Flutter 如何让AppBar sliver 标题垂直居中?

转载 作者:IT王子 更新时间:2023-10-29 06:48:14 26 4
gpt4 key购买 nike

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

""“”“”""""""“”"""""""""""“”“”"""""""""""""""""""""""""""""

最佳答案

您可以使用所需的子级创建一个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: () {/* ... */},
),
],
),
],
));

关于Flutter 如何让AppBar sliver 标题垂直居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51882320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com