Reputation: 1659
Currently I am using this tutorial to learn how to build a Tabbed Appbar in Flutter. What I would like to do is to have different pages with a listview as shown here in each of the tabs. How can this be done or is there a tutorial I can be pointed to?
Upvotes: 1
Views: 8020
Reputation: 1681
I think you want to do something like this, no?
// 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());
}
Upvotes: 5