2022-09-26 13:51:18 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-29 23:12:24 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2022-09-26 13:51:18 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2022-10-08 22:16:35 +02:00
|
|
|
import 'package:adguard_home_manager/config/app_screens.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
2022-09-29 23:12:24 +02:00
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
2022-09-26 16:08:56 +02:00
|
|
|
import 'package:adguard_home_manager/models/app_screen.dart';
|
2022-09-26 13:51:18 +02:00
|
|
|
|
|
|
|
class BottomNavBar extends StatelessWidget {
|
2022-10-08 22:16:35 +02:00
|
|
|
const BottomNavBar({Key? key}) : super(key: key);
|
2022-09-26 13:51:18 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-08 22:16:35 +02:00
|
|
|
final serversProvider = Provider.of<ServersProvider>(context);
|
2022-09-29 23:12:24 +02:00
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
2023-05-25 15:06:21 +02:00
|
|
|
List<AppScreen> screens = serversProvider.selectedServer != null && serversProvider.apiClient != null
|
2022-10-08 22:16:35 +02:00
|
|
|
? screensServerConnected
|
|
|
|
: screensSelectServer;
|
|
|
|
|
2022-09-26 13:51:18 +02:00
|
|
|
String translatedName(String key) {
|
|
|
|
switch (key) {
|
|
|
|
case 'home':
|
|
|
|
return AppLocalizations.of(context)!.home;
|
|
|
|
|
|
|
|
case 'settings':
|
|
|
|
return AppLocalizations.of(context)!.settings;
|
|
|
|
|
2022-09-26 16:08:56 +02:00
|
|
|
case 'connect':
|
|
|
|
return AppLocalizations.of(context)!.connect;
|
|
|
|
|
2022-09-28 15:47:43 +02:00
|
|
|
case 'clients':
|
|
|
|
return AppLocalizations.of(context)!.clients;
|
|
|
|
|
2022-09-30 23:33:57 +02:00
|
|
|
case 'logs':
|
|
|
|
return AppLocalizations.of(context)!.logs;
|
|
|
|
|
2022-10-07 20:48:05 +02:00
|
|
|
case 'filters':
|
|
|
|
return AppLocalizations.of(context)!.filters;
|
|
|
|
|
2022-09-26 13:51:18 +02:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-25 15:06:21 +02:00
|
|
|
if ((serversProvider.selectedServer == null || serversProvider.apiClient == null) && appConfigProvider.selectedScreen > 1) {
|
|
|
|
appConfigProvider.setSelectedScreen(0);
|
|
|
|
}
|
|
|
|
|
2022-09-26 13:51:18 +02:00
|
|
|
return NavigationBar(
|
2023-05-25 15:06:21 +02:00
|
|
|
selectedIndex: (serversProvider.selectedServer == null || serversProvider.apiClient == null) && appConfigProvider.selectedScreen > 1
|
|
|
|
? 0
|
|
|
|
: appConfigProvider.selectedScreen,
|
2022-09-26 13:51:18 +02:00
|
|
|
destinations: screens.map((screen) => NavigationDestination(
|
2023-04-06 22:56:32 +02:00
|
|
|
icon: Stack(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
screen.icon,
|
|
|
|
color: screens[appConfigProvider.selectedScreen] == screen
|
|
|
|
? Theme.of(context).colorScheme.onSecondaryContainer
|
|
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
if (
|
|
|
|
screen.name == 'settings' &&
|
|
|
|
serversProvider.updateAvailable.data != null &&
|
2023-06-08 22:51:15 +02:00
|
|
|
serversProvider.updateAvailable.data!.canAutoupdate == true
|
2023-04-06 22:56:32 +02:00
|
|
|
) Positioned(
|
|
|
|
bottom: 0,
|
|
|
|
right: -12,
|
|
|
|
child: Container(
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
margin: const EdgeInsets.only(right: 12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
color: Colors.red
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2022-10-26 14:45:02 +02:00
|
|
|
),
|
2022-09-26 13:51:18 +02:00
|
|
|
label: translatedName(screen.name)
|
|
|
|
)).toList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|