我想将选项卡放置在水平 PageView 内,并且能够滑出选项卡。在内容区域中,我可以从一个页面滑入选项卡,但不能从选项卡滑出到另一个页面。如果我在 TabBar 上滑动,那么我可以离开选项卡并转到相邻页面。
有没有办法让我从 TabView 内容区域滑动并将其移动到相邻的 PageView 页面?
这是我的测试代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return PageView(
children: <Widget>[
Scaffold(
appBar: AppBar(title: Text('Page 1'),),
body: Center(child: Text('hi'),),
),
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
),
body: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
),
Scaffold(
appBar: AppBar(title: Text('Page 3'),),
body: Center(child: Text('bye'),),
),
],
);
}
}