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-10-04 15:59:01 +02:00
|
|
|
import 'package:flutter_web_browser/flutter_web_browser.dart';
|
2022-09-26 16:08:56 +02:00
|
|
|
|
2022-09-27 17:54:00 +02:00
|
|
|
import 'package:adguard_home_manager/screens/servers/servers.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-09-26 16:08:56 +02:00
|
|
|
class HomeAppBar extends StatelessWidget with PreferredSizeWidget {
|
|
|
|
const HomeAppBar({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
PreferredSizeWidget build(BuildContext context) {
|
2022-09-27 14:29:36 +02:00
|
|
|
final serversProvider = Provider.of<ServersProvider>(context);
|
|
|
|
|
|
|
|
final Server server = serversProvider.selectedServer!;
|
|
|
|
|
2022-09-27 17:54:00 +02:00
|
|
|
void navigateServers() {
|
|
|
|
Future.delayed(const Duration(milliseconds: 0), (() {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => const Servers())
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-10-04 15:59:01 +02:00
|
|
|
void openWebAdminPanel() {
|
|
|
|
FlutterWebBrowser.openWebPage(
|
|
|
|
url: "${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}",
|
|
|
|
customTabsOptions: const CustomTabsOptions(
|
|
|
|
instantAppsEnabled: true,
|
|
|
|
showTitle: true,
|
|
|
|
urlBarHidingEnabled: false,
|
|
|
|
),
|
|
|
|
safariVCOptions: const SafariViewControllerOptions(
|
|
|
|
barCollapsingEnabled: true,
|
|
|
|
dismissButtonStyle: SafariViewControllerDismissButtonStyle.close,
|
|
|
|
modalPresentationCapturesStatusBarAppearance: true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-26 16:08:56 +02:00
|
|
|
return AppBar(
|
2022-09-28 02:51:55 +02:00
|
|
|
toolbarHeight: 70,
|
2022-09-27 14:29:36 +02:00
|
|
|
title: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 5),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
serversProvider.serverStatus.data != null
|
|
|
|
? serversProvider.serverStatus.data!.generalEnabled == true
|
|
|
|
? Icons.gpp_good_rounded
|
|
|
|
: Icons.gpp_bad_rounded
|
|
|
|
: Icons.shield,
|
|
|
|
size: 30,
|
|
|
|
color: serversProvider.serverStatus.data != null
|
|
|
|
? serversProvider.serverStatus.data!.generalEnabled == true
|
|
|
|
? Colors.green
|
|
|
|
: Colors.red
|
|
|
|
: Colors.grey,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
server.name,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 20
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
Text(
|
|
|
|
"${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}",
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
color: Color.fromRGBO(140, 140, 140, 1)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
PopupMenuButton(
|
|
|
|
itemBuilder: (context) => [
|
2022-09-27 17:54:00 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
onTap: navigateServers,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.storage_rounded),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Text(AppLocalizations.of(context)!.servers)
|
|
|
|
],
|
|
|
|
),
|
2022-10-04 15:59:01 +02:00
|
|
|
),
|
|
|
|
if (serversProvider.serverStatus.loadStatus == 1) PopupMenuItem(
|
|
|
|
onTap: openWebAdminPanel,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.web_rounded),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Text(AppLocalizations.of(context)!.webAdminPanel)
|
|
|
|
],
|
|
|
|
),
|
2022-09-27 17:54:00 +02:00
|
|
|
)
|
2022-09-27 14:29:36 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-09-26 16:08:56 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-09-28 02:51:55 +02:00
|
|
|
Size get preferredSize => const Size.fromHeight(70);
|
2022-09-26 16:08:56 +02:00
|
|
|
}
|