У меня есть приложение, которое маршрутизирует мой класс контента, когда пользователь вошел в систему, и оно содержит BottomNavigationBar.Каждый элемент панели навигации является классом, который отображает информацию
final List<Widget> _children = [
HomePage(),
LibraryPage(),
PlaceholderWidget(Colors.green),
PlaceholderWidget(Colors.blue),
PlaceholderWidget(Colors.black)
];
Проблема, с которой я сталкиваюсь, находится в классе HomePage, который является одним из дочерних.У меня есть виджет в AppBar, предназначенный для выхода из системы, поэтому я хотел использовать функцию (_signOut ()) из родительского класса (ContentPage), чтобы он мог выходить из системы с помощью Auth и VoidCallBack, который былпередан из класса маршрутизации (RootPage).Я не могу сделать это статической функцией, потому что я получаю сообщение об ошибке, когда пытаюсь использовать один из членов класса Content.
[dart] Instance members can't be accessed from a static method. [instance_member_access_from_static]
Так что, если что-то было, я могу запустить эту функцию без использованиястатические модификаторы, это было бы замечательно.
class ContentPage extends StatefulWidget {
ContentPage({this.auth, this.onSignedOut});
final BaseAuth auth;
final VoidCallback onSignedOut;
_ContentPageState createState() => _ContentPageState();
}
class _ContentPageState extends State<ContentPage> {
int _currentIndex = 0;
final List<Widget> _children = [
HomePage(),
LibraryPage(),
PlaceholderWidget(Colors.green),
PlaceholderWidget(Colors.blue),
PlaceholderWidget(Colors.black)
];
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
_signout() async {
try {
await widget.auth.signOut();
widget.onSignedOut();
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF000000),
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: onTabTapped,
fixedColor: Colors.black,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
BottomNavigationBarItem(
icon: Icon(Icons.mic),
title: Text('Battle'),
),
BottomNavigationBarItem(
icon: Icon(Icons.message),
title: Text('Messages'),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: Text('Account'),
),
],
),
);
}
}