flutter - 无法在 AppBar Flutter 中放置图像和文本
问题描述
我想将图像和文本放入 appbar,但似乎我无法将我想要的所有内容放入 appbar。
我有这个代码:
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title:Column(
children: [
Container(
child: Image.asset(
'assets/vecteezy_circle-abstract_1191814.png',
fit: BoxFit.scaleDown,
height: 100,
),
),
Container(
padding: const EdgeInsets.only(top: 15),
child: Text('Text'))
],
),
bottom: TabBar(
tabs: [Tab(text: 'tab 1'), Tab(text: 'tab 2')],
),
),
body: TabBarView(children: [
Text("o"),
Text("kk"),
]),
));
}
我有这样的结果: https ://i.stack.imgur.com/jzt4o.png
我怎样才能合适?所以它看起来像这样: https ://i.stack.imgur.com/r0gum.png
解决方案
你需要CustomScrollView
使用SliverAppBar
从Flutter Dev看这个例子
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final title = 'Floating App Bar';
return MaterialApp(
title: title,
home: Scaffold(
// No appbar provided to the Scaffold, only a body with a
// CustomScrollView.
body: CustomScrollView(
slivers: <Widget>[
// Add the app bar to the CustomScrollView.
SliverAppBar(
// Provide a standard title.
title: Text(title),
// Allows the user to reveal the app bar if they begin scrolling
// back up the list of items.
floating: true,
// Display a placeholder widget to visualize the shrinking size.
flexibleSpace: Placeholder(),
// Make the initial height of the SliverAppBar larger than normal.
expandedHeight: 200,
),
// Next, create a SliverList
SliverList(
// Use a delegate to build items as they're scrolled on screen.
delegate: SliverChildBuilderDelegate(
// The builder function returns a ListTile with a title that
// displays the index of the current item.
(context, index) => ListTile(title: Text('Item #$index')),
// Builds 1000 ListTiles
childCount: 1000,
),
),
],
),
),
);
}
}
推荐阅读
- spring-boot - 计划作业正在杀死 Spring Boot 应用程序
- php - NAS Synology,使用 apache .htaccess 进行 url-rewrite
- node.js - Socket.io 监听端口不工作
- wireframe - 是否可以将 html 页面导入 Balsamiq?
- java - if 语句中的变量未正确计数
- kubernetes - 入口或服务类型:LoadBalancer
- php - ERR_INVALID_RESPONSE : php excel 导出代码点火器
- node.js - 如何跨多个用户正确使用数据加载器?
- word2vec - 加载 GoogleNews-vectors-negative300.bin 和 predict_output_word
- c# - Wpf Xaml 更改画布属性“Path.Fill”