Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use page title text by default as source of the top bar title when top bar title is not provided #28

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

ulusoyca
Copy link
Collaborator

@ulusoyca ulusoyca commented Jul 29, 2023

Description

Addresses issue: #26

In many cases, users of this library forget to provide top bar title assuming that their page will never be scrollable. This PR aims to improve the library's usability by providing a default topBarTitle widget using the pageTitle.

The key changes include:

  • If topBarTitle not provided, the data of the pageTitle widget (if it is a Text widget) or the first direct "Text" child of the pageTitle widget will be used as the source of the data for the topBarTitle Text widget.

The following scrollable page produces the attached video. Note that topBarTitle is not provided and the source of the title is the descendent of the pageTitle:

WoltModalSheetPage.withCustomSliverList(
        mainContentPadding: EdgeInsetsDirectional.zero,
        stickyActionBar: StickyActionBarWrapper(
          padding: EdgeInsets.zero,
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child: WoltElevatedButton(
              onPressed: () {
                Navigator.of(modalSheetContext).pop();
                pageIndexNotifier.value = 0;
              },
              child: const Text('Close'),
            ),
          ),
        ),
        pageTitle: const Padding(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: ModalSheetTitle('A very long text as page title to test the look in top bar title.'),
        ),
        heroImageHeight: 200,
        heroImage: const Image(
          image: AssetImage('lib/assets/images/material_colors_hero.png'),
          fit: BoxFit.cover,
        ),
        backButton: WoltModalSheetBackButton(onBackPressed: () {
          pageIndexNotifier.value = pageIndexNotifier.value - 1;
        }),
        closeButton: WoltModalSheetCloseButton(onClosed: () {
          Navigator.of(modalSheetContext).pop();
          pageIndexNotifier.value = 0;
        }),
        sliverList: SliverList(
          delegate: SliverChildBuilderDelegate(
            (_, index) => ColorTile(color: allMaterialColors[index]),
            childCount: allMaterialColors.length,
          ),
        ),
      );
trimmed_title.mov

@ulusoyca ulusoyca requested a review from TahaTesser July 29, 2023 14:31
@ulusoyca ulusoyca force-pushed the issue-26-use-page-title-for-top-bar-title-by-default branch from 3788c6b to 430ce84 Compare July 29, 2023 14:34
Copy link
Collaborator

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comments

import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

void main() {
group('WoltModalSheetTopBarTitle tests', () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment on lines +51 to +74
final topBarTitle = widget.page.topBarTitle;
final pageTitleText =
(widget.page.pageTitle is Text) ? (widget.page.pageTitle as Text).data : this.pageTitleText;

if (topBarTitle != null) {
return topBarTitle;
} else if (pageTitleText != null) {
return Row(
children: [
const SizedBox(width: 72),
Expanded(
child: Text(
pageTitleText,
style: Theme.of(context).textTheme.titleSmall,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
const SizedBox(width: 72),
],
);
}
return const SizedBox.shrink();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be fine as an initial implementation but this needs to be improved.
I would recommend adding a TODO here and an issue in the repository to improve this later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TahaTesser can you please mention how it can be improved?

Copy link
Collaborator

@TahaTesser TahaTesser Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a custom child layout determine the element before the layout happens. Also, it returns a sized box, this widget should. not render at all if there are no conditions met.

The current look-up is only in the init, so what happens if the title text widget is removed? Does it update the widget?

Text is inside Expanded which will render the widget too wide. It should align with the text direction and ability to customize padding. Lower level widget like NavigationToolbar already has these features.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TahaTesser Thanks, in my next PR, I will apply your suggestions. Merging this PR for now.

body: WoltModalSheetTopBarTitle(
page: WoltModalSheetPage.withSingleChild(
child: const SizedBox.shrink(),
topBarTitle: const Text('Top Bar Title'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit move these to constants outside so they can be referenced and easily changed in multiple places

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arpadhani this is a test file. I don't think there is a reason to move these to outside.

@ulusoyca ulusoyca merged commit 9042e56 into main Jul 31, 2023
@alirp88 alirp88 deleted the issue-26-use-page-title-for-top-bar-title-by-default branch January 19, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants