Skip to content

Commit

Permalink
Cleanup TitleBar implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
esDotDev committed May 12, 2021
1 parent 19897df commit 88d29ed
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 111 deletions.
90 changes: 43 additions & 47 deletions lib/views/app_title_bar/app_title_bar.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import 'package:anchored_popups/anchored_popup_region.dart';
import 'package:animate_do/animate_do.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_folio/_utils/device_info.dart';
import 'package:flutter_folio/_utils/input_utils.dart';
import 'package:flutter_folio/_utils/native_window_utils/window_utils.dart';
import 'package:flutter_folio/core_packages.dart';
import 'package:flutter_folio/data/app_user.dart';
import 'package:flutter_folio/models/app_model.dart';
import 'package:flutter_folio/models/books_model.dart';
import 'package:flutter_folio/views/app_title_bar/rounded_profile_button.dart';
import 'package:flutter_folio/views/app_title_bar/touch_mode_toggle_btn.dart';
import 'package:flutter_folio/views/user_profile_card/user_profile_card.dart';
import 'package:flutter_folio/views/user_profile_card/user_profile_form.dart';

part 'app_title_bar_desktop.dart';
part 'app_title_bar_mobile.dart';

class AppTitleBar extends StatelessWidget {
@override
Expand All @@ -25,17 +17,53 @@ class AppTitleBar extends StatelessWidget {
constraints: BoxConstraints(maxHeight: 40),
child: Stack(
children: [
// All titlebars share a bg
ShadowedBg(theme.surface1),
// Switch between mobile and desktop title bars
if (DeviceOS.isDesktopOrWeb) ...[
_AppTitleBarDesktop(),
_AdaptiveTitleBarContent(),
],
),
));
}
}

class _AdaptiveTitleBarContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Determine whether to show back button. We don't want to show it for "guest" users
bool isGuestUser = context.select((AppModel m) => m.isGuestUser);
bool canGoBack = context.select((AppModel m) => m.canPopNav);
bool showBackBtn = isGuestUser == false && canGoBack;
double appWidth = context.widthPx;
// Mac title bar has a different layout as it's window btns are left aligned
bool isMac = DeviceOS.isMacOS;
bool isMobile = DeviceOS.isMobile;

return Stack(children: [
// Centered TitleText
if (appWidth > 400) Center(child: _TitleText()),
// Btns
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (isMac || isMobile) ...[
if (isMac) HSpace(80), // Reserve some space for the native btns
if (showBackBtn) _BackBtn(),
Spacer(),
TouchModeToggleBtn(invertPopupAlign: isMac),
HSpace.sm,
RoundedProfileBtn(invertRow: true, useBottomSheet: isMobile),
HSpace.sm,
] else ...[
_AppTitleBarMobile(),
HSpace.sm,
// Linux and Windows are left aligned and simple
RoundedProfileBtn(useBottomSheet: isMobile),
HSpace.sm,
TouchModeToggleBtn(invertPopupAlign: isMac),
HSpace.sm,
if (showBackBtn) _BackBtn(),
]
],
),
));
]);
}
}

Expand Down Expand Up @@ -73,35 +101,3 @@ class _BackBtn extends StatelessWidget {
context.read<AppModel>().popNav();
}
}

class _AdaptiveProfileBtn extends StatelessWidget {
const _AdaptiveProfileBtn({Key? key, this.useBottomSheet = false, this.invertRow = false}) : super(key: key);
final bool useBottomSheet;
final bool invertRow;
@override
Widget build(BuildContext context) {
AppUser? user = context.select((AppModel m) => m.currentUser);
if (user == null) return Container();
//
Widget profileIcon =
StyledCircleImage(padding: EdgeInsets.all(Insets.xs), url: user.imageUrl ?? AppUser.kDefaultImageUrl);
return useBottomSheet
? SimpleBtn(ignoreDensity: true, onPressed: () => _showProfileSheet(context), child: profileIcon)
: AnchoredPopUpRegion.click(
popChild: ClipRect(
child: UserProfileCard(),
//child: Container(width: 100, height: 100, color: Colors.red),
),
popAnchor: invertRow ? Alignment.topRight : Alignment.topLeft,
anchor: invertRow ? Alignment.bottomRight : Alignment.bottomLeft,
child: profileIcon);
}

void _showProfileSheet(BuildContext context) {
showStyledBottomSheet(context,
child: Container(
padding: EdgeInsets.all(Insets.xl),
child: UserProfileForm(bottomSheet: true),
));
}
}
39 changes: 0 additions & 39 deletions lib/views/app_title_bar/app_title_bar_desktop.dart

This file was deleted.

19 changes: 0 additions & 19 deletions lib/views/app_title_bar/app_title_bar_mobile.dart

This file was deleted.

42 changes: 42 additions & 0 deletions lib/views/app_title_bar/rounded_profile_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:anchored_popups/anchored_popup_region.dart';
import 'package:flutter/material.dart';
import 'package:flutter_folio/core_packages.dart';
import 'package:flutter_folio/data/app_user.dart';
import 'package:flutter_folio/models/app_model.dart';
import 'package:flutter_folio/views/user_profile_card/user_profile_card.dart';
import 'package:flutter_folio/views/user_profile_card/user_profile_form.dart';

class RoundedProfileBtn extends StatelessWidget {
const RoundedProfileBtn({Key? key, this.useBottomSheet = false, this.invertRow = false}) : super(key: key);
final bool useBottomSheet;
final bool invertRow;
@override
Widget build(BuildContext context) {
AppUser? user = context.select((AppModel m) => m.currentUser);
if (user == null) return Container();
//
Widget profileIcon =
StyledCircleImage(padding: EdgeInsets.all(Insets.xs), url: user.imageUrl ?? AppUser.kDefaultImageUrl);
return useBottomSheet
? SimpleBtn(ignoreDensity: true, onPressed: () => _showProfileSheet(context), child: profileIcon)
: AnchoredPopUpRegion.hoverWithClick(
clickPopChild: ClipRect(
child: UserProfileCard(),
//child: Container(width: 100, height: 100, color: Colors.red),
),
hoverPopChild: StyledTooltip("Open User Info panel"),
buttonBuilder: (_, child, show) => SimpleBtn(onPressed: show, child: child),
hoverPopAnchor: invertRow ? Alignment.topRight : Alignment.topLeft,
clickPopAnchor: invertRow ? Alignment.topRight : Alignment.topLeft,
clickAnchor: invertRow ? Alignment.bottomRight : Alignment.bottomLeft,
child: profileIcon);
}

void _showProfileSheet(BuildContext context) {
showStyledBottomSheet(context,
child: Container(
padding: EdgeInsets.all(Insets.xl),
child: UserProfileForm(bottomSheet: true),
));
}
}
2 changes: 0 additions & 2 deletions lib/views/auth_page/auth_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_folio/_widgets/animated/animated_scale.dart';
import 'package:flutter_folio/core_packages.dart';

import 'auth_form.dart';
Expand Down
2 changes: 2 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"

#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
Expand Down
2 changes: 2 additions & 0 deletions linux/flutter/generated_plugin_registrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

import FlutterMacOS
import Foundation

Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages:
name: anchored_popups
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+5"
version: "0.1.0"
animate_do:
dependency: "direct main"
description:
Expand Down Expand Up @@ -49,7 +49,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.0"
version: "2.5.0"
auto_size_text:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1009,7 +1009,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.2.19"
timeago:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
flutter:
sdk: flutter

anchored_popups: ^0.0.1+5
anchored_popups: ^0.1.0
animate_do: ^2.0.0
#todo: land this patch
auto_size_text:
Expand Down
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"

#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
Expand Down
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugin_registrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

Expand Down

0 comments on commit 88d29ed

Please sign in to comment.