目前我正在使用此tutorial来学习如何在Flutter中构建选项卡式Appbar。我想要做的是在每个选项卡中显示带有列表视图的不同页面,如here所示。如何做到这一点,还是有一个我可以指出的教程?
答案 0 :(得分:2)
我想你想做这样的事情,不是吗?
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class TabbedAppBarSample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new DefaultTabController(
length: 3,
child: new Scaffold(
appBar: new AppBar(
title: const Text('Tabbed AppBar'),
bottom: new TabBar(isScrollable: true, tabs: [
new Tab(text: 'Tab 1', icon: new Icon(Icons.directions_car)),
new Tab(text: 'Tab 2', icon: new Icon(Icons.directions_walk)),
new Tab(text: 'Tab 3', icon: new Icon(Icons.directions_bike)),
]),
),
body: new TabBarView(
children: [
new ListView(
children: list,
),
new ListView(
children: list,
),
new ListView(
children: list,
),
],
),
),
),
);
}
}
List<Widget> list = <Widget>[
new ListTile(
title: new Text('CineArts at the Empire',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('85 W Portal Ave'),
leading: new Icon(
Icons.theaters,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('The Castro Theater',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('429 Castro St'),
leading: new Icon(
Icons.theaters,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('Alamo Drafthouse Cinema',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('2550 Mission St'),
leading: new Icon(
Icons.theaters,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('Roxie Theater',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('3117 16th St'),
leading: new Icon(
Icons.theaters,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('United Artists Stonestown Twin',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('501 Buckingham Way'),
leading: new Icon(
Icons.theaters,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('AMC Metreon 16',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('135 4th St #3000'),
leading: new Icon(
Icons.theaters,
color: Colors.blue[500],
),
),
new Divider(),
new ListTile(
title: new Text('K\'s Kitchen',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('757 Monterey Blvd'),
leading: new Icon(
Icons.restaurant,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('Emmy\'s Restaurant',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('1923 Ocean Ave'),
leading: new Icon(
Icons.restaurant,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('Chaiya Thai Restaurant',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('272 Claremont Blvd'),
leading: new Icon(
Icons.restaurant,
color: Colors.blue[500],
),
),
new ListTile(
title: new Text('La Ciccia',
style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0)),
subtitle: new Text('291 30th St'),
leading: new Icon(
Icons.restaurant,
color: Colors.blue[500],
),
),
];
void main() {
runApp(new TabbedAppBarSample());
}