【发布时间】:2020-08-14 18:47:17
【问题描述】:
我尝试集成bubble_bottom_bar,如文档示例(https://pub.dev/packages/bubble_bottom_bar)和Github上的解释(https://github.com/westdabestdb/bubble_bottom_bar/issues/20)所示。但我仍然收到错误:NoSuchMethodError: The method '>' was called on null。尝试调用:>(0)
这是我的代码:
import 'package:flutter/material.dart';
import 'package:bubble_bottom_bar/bubble_bottom_bar.dart';
import 'package:project/pages/page.dart';
import 'package:project/pages/page1.dart';
import 'package:project/pages/page2.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int currentIndex;
void changePage(int index) {
setState(() {
currentIndex = index;
});
}
Widget callPage(int _selectedBar) {
switch (_selectedBar) {
case 0:
return HomePage();
case 1:
return pagePage();
case 2:
return page1Page();
case 3:
return page2Page();
break;
default:
return null;
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('MoneyTracker'),
),
body: this.callPage(this.currentIndex),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
backgroundColor: Colors.red,
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
bottomNavigationBar: BubbleBottomBar(
opacity: .2,
currentIndex: currentIndex,
onTap: changePage,
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
elevation: 8,
fabLocation: BubbleBottomBarFabLocation.end, //new
hasNotch: true, //new
hasInk: true, //new, gives a cute ink effect
inkColor: Colors.black12, //optional, uses theme color if not specified
items: <BubbleBottomBarItem>[
BubbleBottomBarItem(
backgroundColor: Colors.red,
icon: Icon(
Icons.dashboard,
color: Colors.black,
),
activeIcon: Icon(
Icons.dashboard,
color: Colors.red,
),
title: Text("Home")),
BubbleBottomBarItem(
backgroundColor: Colors.deepPurple,
icon: Icon(
Icons.access_time,
color: Colors.black,
),
activeIcon: Icon(
Icons.access_time,
color: Colors.deepPurple,
),
title: Text("Logs")),
BubbleBottomBarItem(
backgroundColor: Colors.indigo,
icon: Icon(
Icons.folder_open,
color: Colors.black,
),
activeIcon: Icon(
Icons.folder_open,
color: Colors.indigo,
),
title: Text("Folders")),
BubbleBottomBarItem(
backgroundColor: Colors.green,
icon: Icon(
Icons.menu,
color: Colors.black,
),
activeIcon: Icon(
Icons.menu,
color: Colors.green,
),
title: Text("Menu"))
],
),
【问题讨论】:
-
错误是哪一行?
-
声明当前索引为
int currentIndex = 0;