import 'package:flutter/material.dart'; import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:topic/HomePage.dart'; import 'HistoricalRecord.dart'; import 'KnowledgePage.dart'; import 'MessagePage.dart'; import 'PersonalInfo.dart'; import 'generated/l10n.dart'; class BottomNavBar extends StatefulWidget { const BottomNavBar({ super.key, required this.email, required this.initTabIndex, }); final String email; final int initTabIndex; @override State createState() => _BottomNavBarState(); } class _BottomNavBarState extends State { List _tabs(BuildContext context) => [ PersistentTabConfig.noScreen( item: ItemConfig( icon: Icon(Icons.home), title: S.of(context).home, activeForegroundColor: Colors.orange, inactiveForegroundColor: Colors.grey, ), onPressed: (context) { Navigator.push( context, MaterialPageRoute(builder: (context) => HomePage(email: widget.email)), ).then((value) => setState(() {})); }, ), PersistentTabConfig( screen: HistoricalRecord( email: widget.email, ), item: ItemConfig( icon: Icon(Icons.history_edu), title: S.of(context).fall_record, activeForegroundColor: Colors.orange, inactiveForegroundColor: Colors.grey, ), ), PersistentTabConfig( screen: KnowledgePage( email: widget.email, ), item: ItemConfig( icon: Icon(Icons.lightbulb_outline), title: S.of(context).additional_information, activeForegroundColor: Colors.orange, inactiveForegroundColor: Colors.grey, ), ), PersistentTabConfig( screen: MessagePage( email: widget.email, ), item: ItemConfig( icon: Icon(Icons.monitor_outlined), title: S.of(context).switch_camera, activeForegroundColor: Colors.orange, inactiveForegroundColor: Colors.grey, ), ), PersistentTabConfig( screen: PersonalInfo( email: widget.email, ), item: ItemConfig( icon: Icon(Icons.person_sharp), title: S.of(context).personal_information, activeForegroundColor: Colors.orange, inactiveForegroundColor: Colors.grey, ), ), ]; @override void initState() { super.initState(); _setLanguage(); } void _setLanguage() async { SharedPreferences prefs = await SharedPreferences.getInstance(); String preLanguage = prefs.getString("language") ?? ""; Locale locale = preLanguage == "" ? Localizations.localeOf(context) : Locale(preLanguage) ; S.load(locale); setState(() {}); } @override Widget build(BuildContext context) { return PersistentTabView( tabs: _tabs(context), // Pass context here navBarBuilder: (navBarConfig) => Style1BottomNavBar( navBarConfig: navBarConfig, ), controller: PersistentTabController(initialIndex: widget.initTabIndex), ); } }