|
| 1 | +import 'package:flutterx/imports/exports.dart'; |
| 2 | +import '../assets/grouped_icons.dart'; |
| 3 | + |
| 4 | +NavigationBar? buildBottomNavigationBar(AppNotifier provider, String url) { |
| 5 | + return (provider.state.links.length > 1) |
| 6 | + ? NavigationBar( |
| 7 | + // backgroundColor: hexToColor("#4285F4"), |
| 8 | + destinations: [ |
| 9 | + for (var item in provider.state.links) |
| 10 | + NavigationDestination( |
| 11 | + tooltip: item['tooltip'], |
| 12 | + selectedIcon: |
| 13 | + groupedIcons['selectedIcon'] == null |
| 14 | + ? null |
| 15 | + : Icon(groupedIcons['selectedIcon']), |
| 16 | + icon: Icon( |
| 17 | + groupedIcons[item['icon']!.toLowerCase()] ?? |
| 18 | + groupedIcons['info'], |
| 19 | + ), |
| 20 | + label: item['label']!.toUpperCase(), |
| 21 | + ), |
| 22 | + ], |
| 23 | + selectedIndex: |
| 24 | + provider |
| 25 | + .state |
| 26 | + .index, // Set the current index for the BottomNavigationBar |
| 27 | + onDestinationSelected: (selectedIndex) async { |
| 28 | + provider.setIndex(selectedIndex); |
| 29 | + url = provider.state.links[provider.state.index]['url']; |
| 30 | + // Load the corresponding URL in the WebView |
| 31 | + if (provider.state.controller != null) { |
| 32 | + if (provider.state.index == 0) { |
| 33 | + provider.state.controller?.loadUrl( |
| 34 | + urlRequest: URLRequest(url: WebUri(url.toString())), |
| 35 | + ); |
| 36 | + } else { |
| 37 | + provider.state.controller?.loadUrl( |
| 38 | + urlRequest: URLRequest( |
| 39 | + url: WebUri( |
| 40 | + provider.state.links[selectedIndex]['url'].toString(), |
| 41 | + ), |
| 42 | + ), |
| 43 | + ); |
| 44 | + } |
| 45 | + } |
| 46 | + }, |
| 47 | + ) |
| 48 | + : null; |
| 49 | +} |
0 commit comments