2022-09-26 16:08:56 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-27 14:29:36 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2022-09-26 16:08:56 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2022-09-27 17:54:00 +02:00
|
|
|
import 'package:adguard_home_manager/screens/servers/servers.dart';
|
|
|
|
|
2023-10-29 14:31:11 +01:00
|
|
|
import 'package:adguard_home_manager/functions/desktop_mode.dart';
|
2023-05-24 13:51:22 +02:00
|
|
|
import 'package:adguard_home_manager/constants/enums.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/status_provider.dart';
|
2023-05-04 20:23:29 +02:00
|
|
|
import 'package:adguard_home_manager/functions/open_url.dart';
|
2022-09-27 14:29:36 +02:00
|
|
|
import 'package:adguard_home_manager/models/server.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
2022-10-26 15:22:50 +02:00
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
2022-09-27 14:29:36 +02:00
|
|
|
|
2023-05-18 02:14:19 +02:00
|
|
|
class HomeAppBar extends StatelessWidget {
|
|
|
|
final bool innerBoxScrolled;
|
|
|
|
|
|
|
|
const HomeAppBar({
|
|
|
|
Key? key,
|
|
|
|
required this.innerBoxScrolled
|
|
|
|
}) : super(key: key);
|
2022-09-26 16:08:56 +02:00
|
|
|
|
|
|
|
@override
|
2023-05-18 02:14:19 +02:00
|
|
|
Widget build(BuildContext context) {
|
2022-09-27 14:29:36 +02:00
|
|
|
final serversProvider = Provider.of<ServersProvider>(context);
|
2023-05-24 13:51:22 +02:00
|
|
|
final statusProvider = Provider.of<StatusProvider>(context);
|
2022-10-26 15:22:50 +02:00
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
2022-09-27 14:29:36 +02:00
|
|
|
|
2023-10-28 22:38:49 +02:00
|
|
|
final width = MediaQuery.of(context).size.width;
|
|
|
|
|
2022-10-20 16:10:05 +02:00
|
|
|
final Server? server = serversProvider.selectedServer;
|
2022-09-27 14:29:36 +02:00
|
|
|
|
2022-09-27 17:54:00 +02:00
|
|
|
void navigateServers() {
|
|
|
|
Future.delayed(const Duration(milliseconds: 0), (() {
|
2023-10-29 15:38:17 +01:00
|
|
|
Navigator.of(context).push(
|
2022-09-27 17:54:00 +02:00
|
|
|
MaterialPageRoute(builder: (context) => const Servers())
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2023-05-18 02:14:19 +02:00
|
|
|
return SliverAppBar.large(
|
|
|
|
pinned: true,
|
|
|
|
floating: true,
|
|
|
|
centerTitle: false,
|
|
|
|
forceElevated: innerBoxScrolled,
|
2023-10-28 22:38:49 +02:00
|
|
|
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
|
2023-05-25 18:30:44 +02:00
|
|
|
leading: Stack(
|
|
|
|
children: [
|
|
|
|
Center(
|
|
|
|
child: Icon(
|
|
|
|
serversProvider.selectedServer != null && statusProvider.serverStatus != null
|
|
|
|
? statusProvider.serverStatus!.generalEnabled == true
|
|
|
|
? Icons.gpp_good_rounded
|
|
|
|
: Icons.gpp_bad_rounded
|
|
|
|
: Icons.shield,
|
|
|
|
size: 30,
|
|
|
|
color: serversProvider.selectedServer != null && statusProvider.serverStatus != null
|
|
|
|
? statusProvider.serverStatus!.generalEnabled == true
|
|
|
|
? appConfigProvider.useThemeColorForStatus
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.onSurface.withOpacity(0.38)
|
|
|
|
: Colors.red
|
|
|
|
: Theme.of(context).colorScheme.onSurface.withOpacity(0.38)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (statusProvider.remainingTime > 0) Positioned(
|
|
|
|
bottom: 15,
|
|
|
|
right: 15,
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.all(1),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(30),
|
|
|
|
color: Theme.of(context).colorScheme.surface
|
|
|
|
),
|
|
|
|
child: Icon(
|
|
|
|
Icons.timer_rounded,
|
|
|
|
size: 12,
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2023-05-18 02:14:19 +02:00
|
|
|
),
|
|
|
|
title: Column(
|
2023-05-18 11:13:03 +02:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
2023-05-18 02:14:19 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (serversProvider.selectedServer != null) ...[
|
|
|
|
Text(
|
|
|
|
server!.name,
|
2023-09-09 21:25:21 +02:00
|
|
|
style: !appConfigProvider.hideServerAddress ? const TextStyle(
|
2023-05-18 02:14:19 +02:00
|
|
|
fontSize: 20
|
2023-09-09 21:25:21 +02:00
|
|
|
) : null,
|
2022-09-27 14:29:36 +02:00
|
|
|
),
|
2023-09-09 21:25:21 +02:00
|
|
|
if (!appConfigProvider.hideServerAddress) ...[
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
Text(
|
|
|
|
"${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]
|
2022-09-27 14:29:36 +02:00
|
|
|
],
|
2023-05-18 02:14:19 +02:00
|
|
|
if (serversProvider.selectedServer == null) Text(
|
|
|
|
AppLocalizations.of(context)!.noServerSelected,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 20
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-09-27 14:29:36 +02:00
|
|
|
),
|
2023-05-18 02:14:19 +02:00
|
|
|
actions: [
|
|
|
|
PopupMenuButton(
|
|
|
|
itemBuilder: (context) => [
|
|
|
|
PopupMenuItem(
|
|
|
|
onTap: navigateServers,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.storage_rounded),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Text(AppLocalizations.of(context)!.servers)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-05-24 13:51:22 +02:00
|
|
|
if (serversProvider.selectedServer != null && statusProvider.loadStatus == LoadStatus.loaded) PopupMenuItem(
|
2023-05-18 02:14:19 +02:00
|
|
|
onTap: () => openUrl("${server!.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}"),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.web_rounded),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Text(AppLocalizations.of(context)!.webAdminPanel)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
2022-09-26 16:08:56 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|