New appbar on homescreen

This commit is contained in:
Juan Gilsanz Polo 2023-05-18 02:14:19 +02:00
parent f6254fe8a3
commit 1d7c269aa0
3 changed files with 120 additions and 113 deletions

View file

@ -1,5 +1,3 @@
import 'package:intl/intl.dart';
bool? convertFromIntToBool(int value) {
if (value == 1) {
return true;

View file

@ -9,11 +9,16 @@ import 'package:adguard_home_manager/models/server.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart';
class HomeAppBar extends StatelessWidget implements PreferredSizeWidget {
const HomeAppBar({Key? key}) : super(key: key);
class HomeAppBar extends StatelessWidget {
final bool innerBoxScrolled;
const HomeAppBar({
Key? key,
required this.innerBoxScrolled
}) : super(key: key);
@override
PreferredSizeWidget build(BuildContext context) {
Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context);
@ -27,93 +32,81 @@ class HomeAppBar extends StatelessWidget implements PreferredSizeWidget {
}));
}
return AppBar(
toolbarHeight: 70,
title: Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: [
Icon(
serversProvider.selectedServer != null && serversProvider.serverStatus.data != null
? serversProvider.serverStatus.data!.generalEnabled == true
? Icons.gpp_good_rounded
: Icons.gpp_bad_rounded
: Icons.shield,
size: 30,
color: serversProvider.selectedServer != null && serversProvider.serverStatus.data != null
? serversProvider.serverStatus.data!.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)
),
const SizedBox(width: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (serversProvider.selectedServer != null) ...[
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: TextStyle(
fontSize: 14,
color: Theme.of(context).listTileTheme.textColor
),
)
],
if (serversProvider.selectedServer == null) Text(
AppLocalizations.of(context)!.noServerSelected,
style: const TextStyle(
fontSize: 20
),
),
],
),
],
return SliverAppBar.large(
pinned: true,
floating: true,
centerTitle: false,
forceElevated: innerBoxScrolled,
leading: Icon(
serversProvider.selectedServer != null && serversProvider.serverStatus.data != null
? serversProvider.serverStatus.data!.generalEnabled == true
? Icons.gpp_good_rounded
: Icons.gpp_bad_rounded
: Icons.shield,
size: 30,
color: serversProvider.selectedServer != null && serversProvider.serverStatus.data != null
? serversProvider.serverStatus.data!.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)
),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (serversProvider.selectedServer != null) ...[
Text(
server!.name,
style: const TextStyle(
fontSize: 20
),
),
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem(
onTap: navigateServers,
child: Row(
children: [
const Icon(Icons.storage_rounded),
const SizedBox(width: 10),
Text(AppLocalizations.of(context)!.servers)
],
),
),
if (serversProvider.selectedServer != null && serversProvider.serverStatus.loadStatus == 1) PopupMenuItem(
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)
],
),
)
]
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
),
)
],
),
if (serversProvider.selectedServer == null) Text(
AppLocalizations.of(context)!.noServerSelected,
style: const TextStyle(
fontSize: 20
),
),
],
),
actions: [
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem(
onTap: navigateServers,
child: Row(
children: [
const Icon(Icons.storage_rounded),
const SizedBox(width: 10),
Text(AppLocalizations.of(context)!.servers)
],
),
),
if (serversProvider.selectedServer != null && serversProvider.serverStatus.loadStatus == 1) PopupMenuItem(
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)
],
),
)
]
)
],
);
}
@override
Size get preferredSize => const Size.fromHeight(70);
}

View file

@ -83,7 +83,6 @@ class _HomeState extends State<Home> {
case 1:
return ListView(
controller: scrollController,
children: [
ServerStatus(serverStatus: serversProvider.serverStatus.data!),
Padding(
@ -261,31 +260,48 @@ class _HomeState extends State<Home> {
}
return Scaffold(
appBar: const HomeAppBar(),
body: RefreshIndicator(
color: Theme.of(context).colorScheme.primary,
onRefresh: () async {
final result = await getServerStatus(serversProvider.selectedServer!);
if (result['result'] == 'success') {
serversProvider.setServerStatusData(result['data']);
}
else {
appConfigProvider.addLog(result['log']);
showSnacbkar(
appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.serverStatusNotRefreshed,
color: Colors.red
);
}
},
child: status()
body: Stack(
children: [
NestedScrollView(
controller: scrollController,
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: HomeAppBar(innerBoxScrolled: innerBoxIsScrolled,)
)
],
body: RefreshIndicator(
color: Theme.of(context).colorScheme.primary,
onRefresh: () async {
final result = await getServerStatus(serversProvider.selectedServer!);
if (result['result'] == 'success') {
serversProvider.setServerStatusData(result['data']);
}
else {
appConfigProvider.addLog(result['log']);
showSnacbkar(
appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.serverStatusNotRefreshed,
color: Colors.red
);
}
},
child: status()
),
),
AnimatedPositioned(
duration: const Duration(milliseconds: 100),
curve: Curves.easeInOut,
bottom: isVisible == true ?
appConfigProvider.showingSnackbar
? 70
: 20
: -70,
right: 20,
child: const HomeFab()
),
],
),
floatingActionButton: appConfigProvider.showingSnackbar
? null
: isVisible
? const HomeFab()
: null
);
}
}