Browse Source

Merge pull request #362 from Leptopoda/feature/adaptive-layout

neon: refractor HomePage
pull/364/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
1f94382948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 92
      packages/neon/neon/lib/src/pages/home.dart

92
packages/neon/neon/lib/src/pages/home.dart

@ -183,22 +183,13 @@ class _HomePageState extends State<HomePage> {
) => ) =>
OptionBuilder<NavigationMode>( OptionBuilder<NavigationMode>(
option: _globalOptions.navigationMode, option: _globalOptions.navigationMode,
builder: (final context, final navigationMode) => WillPopScope( builder: (final context, final navigationMode) {
onWillPop: () async { final accounts = accountsSnapshot.data;
if (_scaffoldKey.currentState!.isDrawerOpen) { final account = accounts?.find(_account.id);
Navigator.pop(context); if (accounts == null || account == null) {
return true; return const Scaffold();
} }
_scaffoldKey.currentState!.openDrawer();
return false;
},
child: Builder(
builder: (final context) {
if (accountsSnapshot.hasData) {
final accounts = accountsSnapshot.data!;
final account = accounts.find(_account.id);
if (account != null) {
final isQuickBar = navigationMode == NavigationMode.quickBar; final isQuickBar = navigationMode == NavigationMode.quickBar;
final drawer = Builder( final drawer = Builder(
builder: (final context) => Drawer( builder: (final context) => Drawer(
@ -263,18 +254,15 @@ class _HomePageState extends State<HomePage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
if (capabilities.data != null) ...[ if (capabilities.data != null) ...[
if (capabilities.data!.capabilities.theming?.name != if (capabilities.data!.capabilities.theming?.name != null) ...[
null) ...[
Text( Text(
capabilities.data!.capabilities.theming!.name!, capabilities.data!.capabilities.theming!.name!,
style: DefaultTextStyle.of(context).style.copyWith( style: DefaultTextStyle.of(context).style.copyWith(
color: color: Theme.of(context).appBarTheme.foregroundColor,
Theme.of(context).appBarTheme.foregroundColor,
), ),
), ),
], ],
if (capabilities.data!.capabilities.theming?.logo != if (capabilities.data!.capabilities.theming?.logo != null) ...[
null) ...[
Flexible( Flexible(
child: NeonCachedUrlImage( child: NeonCachedUrlImage(
url: capabilities.data!.capabilities.theming!.logo!, url: capabilities.data!.capabilities.theming!.logo!,
@ -295,8 +283,7 @@ class _HomePageState extends State<HomePage> {
child: DropdownButton<String>( child: DropdownButton<String>(
isExpanded: true, isExpanded: true,
dropdownColor: Theme.of(context).colorScheme.primary, dropdownColor: Theme.of(context).colorScheme.primary,
iconEnabledColor: iconEnabledColor: Theme.of(context).colorScheme.onBackground,
Theme.of(context).colorScheme.onBackground,
value: _account.id, value: _account.id,
items: accounts items: accounts
.map<DropdownMenuItem<String>>( .map<DropdownMenuItem<String>>(
@ -305,9 +292,8 @@ class _HomePageState extends State<HomePage> {
child: NeonAccountTile( child: NeonAccountTile(
account: account, account: account,
dense: true, dense: true,
textColor: Theme.of(context) textColor:
.appBarTheme Theme.of(context).appBarTheme.foregroundColor,
.foregroundColor,
), ),
), ),
) )
@ -418,18 +404,7 @@ class _HomePageState extends State<HomePage> {
), ),
), ),
); );
final appBar = AppBar(
return Row(
children: [
if (navigationMode == NavigationMode.drawerAlwaysVisible) ...[
drawer,
],
Expanded(
child: Scaffold(
key: _scaffoldKey,
resizeToAvoidBottomInset: false,
drawer: navigationMode == NavigationMode.drawer ? drawer : null,
appBar: AppBar(
scrolledUnderElevation: navigationMode != NavigationMode.drawer ? 0 : null, scrolledUnderElevation: navigationMode != NavigationMode.drawer ? 0 : null,
automaticallyImplyLeading: navigationMode == NavigationMode.drawer, automaticallyImplyLeading: navigationMode == NavigationMode.drawer,
leadingWidth: isQuickBar ? kQuickBarWidth : null, leadingWidth: isQuickBar ? kQuickBarWidth : null,
@ -452,9 +427,7 @@ class _HomePageState extends State<HomePage> {
if (appImplementations.data != null && activeAppIDSnapshot.hasData) ...[ if (appImplementations.data != null && activeAppIDSnapshot.hasData) ...[
Flexible( Flexible(
child: Text( child: Text(
appImplementations.data! appImplementations.data!.find(activeAppIDSnapshot.data!)!.name(context),
.find(activeAppIDSnapshot.data!)!
.name(context),
), ),
), ),
], ],
@ -529,8 +502,10 @@ class _HomePageState extends State<HomePage> {
), ),
), ),
], ],
), );
body: Row(
final body = Builder(
builder: (final context) => Row(
children: [ children: [
if (navigationMode == NavigationMode.quickBar) ...[ if (navigationMode == NavigationMode.quickBar) ...[
drawer, drawer,
@ -543,8 +518,7 @@ class _HomePageState extends State<HomePage> {
Expanded( Expanded(
child: Center( child: Center(
child: Text( child: Text(
AppLocalizations.of(context) AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound,
.errorNoCompatibleNextcloudAppsFound,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
), ),
@ -564,16 +538,36 @@ class _HomePageState extends State<HomePage> {
), ),
], ],
), ),
),
),
],
); );
return WillPopScope(
onWillPop: () async {
if (_scaffoldKey.currentState!.isDrawerOpen) {
Navigator.pop(context);
return true;
} }
}
return const Scaffold(); _scaffoldKey.currentState!.openDrawer();
return false;
}, },
child: Row(
children: [
if (navigationMode == NavigationMode.drawerAlwaysVisible) ...[
drawer,
],
Expanded(
child: Scaffold(
key: _scaffoldKey,
resizeToAvoidBottomInset: false,
drawer: navigationMode == NavigationMode.drawer ? drawer : null,
appBar: appBar,
body: body,
),
), ),
],
), ),
);
},
), ),
), ),
), ),

Loading…
Cancel
Save