下午好,我是flutter的新手,我正在嘗試使用curved_navigation_bar,但是我不知道如何設(shè)置頁面導(dǎo)航,這是我的代碼,索引0將轉(zhuǎn)到news.dart頁面,索引1將轉(zhuǎn)到cells.dart頁面,索引2將轉(zhuǎn)到home.dart頁面,索引3轉(zhuǎn)到book.dart頁面,索引4轉(zhuǎn)到info.dart頁面,出現(xiàn)的第一個頁面是索引2,非常感謝。
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:statistik_malang/body.dart';
import 'package:statistik_malang/constants.dart';
class HomeScreen extends StatefulWidget {
// const HomeScreen({ Key? key }) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(),
body: Body(),
extendBody: true,
bottomNavigationBar: CurvedNavigationBar(
backgroundColor: Colors.transparent,
buttonBackgroundColor: kPrimaryColor,
animationDuration: Duration(milliseconds: 300),
height: 50,
items: <Widget>[
SvgPicture.asset(
"assets/icons/news.svg",
width: 20.0,
height: 20.0,
),
SvgPicture.asset(
"assets/icons/cells.svg",
width: 20.0,
height: 20.0,
),
SvgPicture.asset(
"assets/icons/home.svg",
width: 20.0,
height: 20.0,
),
SvgPicture.asset(
"assets/icons/book.svg",
width: 20.0,
height: 20.0,
),
SvgPicture.asset(
"assets/icons/information.svg",
width: 20.0,
height: 20.0,
),
],
onTap: (index) {},
),
);
}
}
只需添加navigationKey并以0開始索引,它就會得到解決
Edited: