[英]Is there a way to put tabs inside a drawer in Flutter?
我目前是 Flutter 的新手,正在尋求有關我正在嘗試實現的功能的幫助。 目前我的抽屜里有太多信息,所以我試圖在抽屜里放標簽,這樣人們就可以訪問抽屜里的不同類型的信息。 我對一張照片進行了 Photoshop 處理,以展示我腦海中的想法。 此處顯示帶有標簽圖片的抽屜。 到目前為止,我已經嘗試過 DefaultTabController 但無法讓它工作,所以如果有人有任何其他想法或不同的方法來處理它,我將非常感激。
提前致謝!
您可以在下面復制粘貼運行完整代碼
你可以用Drawer
包裝DefaultTabController
代碼片段
return Scaffold(
...
drawer: Drawer(
child: DefaultTabController(
length: 3,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
),
Container(
height: 50,
color: Colors.black12,
child: TabBar(
labelColor: Colors.deepOrange,
unselectedLabelColor: Colors.white,
tabs: [
Tab(text: "First"),
Tab(text: "Second"),
Tab(text: "Third"),
]),
),
Expanded(
child: Container(
color: Colors.green,
child: TabBarView(children: [
Container(
child: Text("First Body"),
),
Container(
child: Text("Second Body"),
),
Container(
child: Text("Third Body"),
),
]),
),
),
],
),
),
),
工作演示
完整代碼
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,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
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> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
drawer: Drawer(
child: DefaultTabController(
length: 3,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
),
Container(
height: 50,
color: Colors.black12,
child: TabBar(
labelColor: Colors.deepOrange,
unselectedLabelColor: Colors.white,
tabs: [
Tab(text: "First"),
Tab(text: "Second"),
Tab(text: "Third"),
]),
),
Expanded(
child: Container(
color: Colors.green,
child: TabBarView(children: [
Container(
child: Text("First Body"),
),
Container(
child: Text("Second Body"),
),
Container(
child: Text("Third Body"),
),
]),
),
),
],
),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.