如何使一个梯度底部导航栏在颤动?


// ignore_for_file: prefer_const_literals_to_create_immutables, prefer_const_constructors
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart';
import 'package:rent_project/Ui/Auth/Account_screen.dart';
import 'package:rent_project/Ui/Auth/cart_scree.dart';
import 'package:rent_project/Ui/Auth/home_Screen2.dart';
import 'package:rent_project/Ui/Auth/message_screen.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[

Home_Screen(),
Msg_Screen(),
Cart_Screen(),
AccountScreen(),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(

body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: GradientBottomNavigationBar(
backgroundColorStart: Colors.purple,
backgroundColorEnd: Colors.white,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
backgroundColor: Colors.purple,
),
BottomNavigationBarItem(
icon: Icon(Icons.message),
label: 'Message',
backgroundColor: Colors.purple,
),
BottomNavigationBarItem(
icon: Icon(Icons.shop),
label: 'Cart',
backgroundColor: Colors.purple,
),
BottomNavigationBarItem(
icon: Icon(Icons.account_box),
label: 'Account',
backgroundColor: Colors.purple,
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
);
}

}

我在flutter的网站上看到了GradientBottonNavigationBar的示例代码,他们使用了项目的标题,但是当我使用标题而不是标签时,它会给我错误,也不接受标签。

帮我解决这个问题,

我该怎么做呢?标签也给我错误和标题也制造麻烦.....

Try correcting the name to the name of an existing getter, or defining a getter or field named 'title'.
child: item.title

我建议不要使用一个不是空安全的包,即使在为flutter发布了一年的空安全特性之后。

您可以使用以下要点https://gist.github.com/erayerdin/5f2cbd1b52464cf06d199ba6607eaa73

基本上,它使用堆栈来创建渐变,并使底部导航栏的背景透明,以达到相同的效果。

问题在于软件包本身,它使用的是标题而不是label,您可以检查此pr并创建本地文件

你需要在label上传递String

BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
backgroundColor: Colors.purple,
),

最新更新