我正在考慮——如果我在底部需要更多選單元素——我可以將我的 Scaffold bottomNavigationBar 包裝到 ListView 并水平滾動它嗎?
// below code is wrong, but it shows my idea clearly (I suppose :) )
// piece of Scaffold
bottomNavigationBar: BottomNavigationBar(
items: [
ListView(
children: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Q"),
BottomNavigationBarItem(
icon: Icon(Icons.contact_mail), label: "W"),
BottomNavigationBarItem(
icon: Icon(Icons.contact_page), label: "E"),
BottomNavigationBarItem(icon: Icon(Icons.search), label: "R"),
],
)
],
),
uj5u.com熱心網友回復:
使用 BottomAppBar:
bottomNavigationBar: BottomAppBar(
child: ListView(
或者
另一種方法是使用 Tabbar:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return DefaultTabController(
initialIndex: 1,
length: 9,
child: Scaffold(
appBar: AppBar(
title: const Text('TabBar Widget'),
),
body: Column(
children: [
Expanded(
child: const TabBarView(
children: <Widget>[
Center(
child: Text("It's cloudy here"),
),
Center(
child: Text("It's rainy here"),
),
Center(
child: Text("It's sunny here"),
),
Center(
child: Text("It's cloudy here"),
),
Center(
child: Text("It's rainy here"),
),
Center(
child: Text("It's sunny here"),
),
Center(
child: Text("It's cloudy here"),
),
Center(
child: Text("It's rainy here"),
),
Center(
child: Text("It's sunny here"),
),
],
),
),
Container(
color: Colors.blue,
child: const TabBar(
isScrollable: true,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
Tab(
icon: Icon(Icons.cloud_outlined),
),
Tab(
icon: Icon(Icons.beach_access_sharp),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
),
],
),
),
],
),
),
);
}
}
uj5u.com熱心網友回復:
ListView當您bottomNavigationBar有 3 個或更多專案時,您不需要。你只需要type: BottomNavigationBarType.fixed在你的下面添加bottomNavigationBar: BottomNavigationBar()
一個例子 :-
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed, // This is all you need!
items: // ...,
)
欲了解更多資訊,請訪問以下鏈接。
堆疊溢位時的底部導航欄問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418807.html
標籤:
