Skip to content

Conversation

@TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Jan 3, 2024

fixes Invisible SliverAppBar title in Material 3 light theme
fixes FlexibleSpaceBar title is misaligned without the leading widget

Previous attempt #138611


Description

  • fixes the FlexibleSpaceBar centered title position when there is a leading widget.
  • fixes the FlexibleSpaceBar title color for Material 3.
  • Added documentation when using a long FlexibleSpaceBar title and update its test.
  • Improved documentation of default title padding.

Code sample

Code sample

expand to view the code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Example(),
    );
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: SafeArea(
          child: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            leading: Icon(Icons.favorite_rounded),
            flexibleSpace: FlexibleSpaceBar(
              title: ColoredBox(
                color: Color(0xffff0000),
                child: Text('SliverAppBar'),
              ),
            ),
          ),
        ],
      )),
    );
  }
}

Before

Screenshot 2024-01-03 at 18 02 25

After

Screenshot 2024-01-03 at 18 02 16

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 3, 2024
@TahaTesser TahaTesser requested a review from Piinks January 3, 2024 16:07
Comment on lines 102 to 104
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// If the length of the title is greater than the available space, set
/// this property to false, this aligns the title to the start of the
/// flexible space bar and applies [titlePadding] to the title.
/// If the length of the title is greater than the available space, set
/// this property to false. This aligns the title to the start of the
/// flexible space bar and applies [titlePadding] to the title.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there anyway we can do this automatically? Just curious since how much space is available versus how much space text will take up is really hard for developers to anticipate or know ahead of time.

Copy link
Member Author

@TahaTesser TahaTesser Jan 8, 2024

Choose a reason for hiding this comment

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

It is hard automate without introducing a lot more complexity. it will require calculating the screen width, leading widget width, and the total width of the all the actions widgets. Available space could vary between different devices (mobile, tablet, desktop, web) as a result more or less space could be available for a long title.

Official guidelines actually recommend using the large app bar instead, when the title text is long.

Screenshot 2024-01-08 at 13 13 15

I added above documentation to address #132030 concerns, for anyone trying to use regular app bar with a long title in Flutter, they can align the title to left which will provide a default titlePadding.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok thank you for explaining! I figured but wanted to double check. Thanks for adding to the docs about this scenario.

@TahaTesser TahaTesser force-pushed the fix_flexible_space_bar_title branch from a2edd79 to d6b48b5 Compare January 8, 2024 11:36
@TahaTesser TahaTesser requested a review from Piinks January 8, 2024 11:38
@TahaTesser TahaTesser force-pushed the fix_flexible_space_bar_title branch from d6b48b5 to f6615b1 Compare January 9, 2024 08:29
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@TahaTesser TahaTesser added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 12, 2024
@auto-submit auto-submit bot merged commit e20d34c into flutter:master Jan 12, 2024
@TahaTesser TahaTesser deleted the fix_flexible_space_bar_title branch January 12, 2024 13:29
@emersion
Copy link

Thanks a lot for the fix!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 12, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jan 12, 2024
flutter/flutter@9f2e681...7dc856a

2024-01-12 [email protected] Revert "Reverts "Run iOS staging tests with Xcode 15.2"" (flutter/flutter#141420)
2024-01-12 [email protected] Roll Packages from 0744fe6 to d74d687 (5 revisions) (flutter/flutter#141449)
2024-01-12 [email protected] Fix `FlexibleSpaceBar` centered title position and title color (flutter/flutter#140883)
2024-01-12 [email protected] Do not reset framework checkout before running customer tests (flutter/flutter#141013)
2024-01-12 [email protected] Increase delay for checking integration_ui_keyboard_resize test success (flutter/flutter#141301)
2024-01-12 [email protected] Add osx_sdk context for mac builds. (flutter/flutter#141422)
2024-01-12 [email protected] Roll Flutter Engine from ecdaed76f284 to 44a0a6ee4d39 (18 revisions) (flutter/flutter#141432)
2024-01-12 [email protected] Add support for Gradle Kotlin DSL (flutter/flutter#140744)
2024-01-12 [email protected] Fix typo (flutter/flutter#141426)
2024-01-11 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Run iOS staging tests with Xcode 15.2" (flutter/flutter#141412)
2024-01-11 [email protected] Run iOS staging tests with Xcode 15.2 (flutter/flutter#141392)
2024-01-11 [email protected] Fix `ListWheelScrollView` in an `AnimatedContainer` with zero height throw an error (flutter/flutter#141372)
2024-01-11 [email protected] make asset_test.dart tests not dependent on context (flutter/flutter#141331)
2024-01-11 [email protected] Expose 'enable' property to allow the user to disable the SearchBar (flutter/flutter#137388)
2024-01-11 [email protected] Add impeller key to skia gold client, Turn on a framework test shard that will run unit tests with --enable-impeller (flutter/flutter#141341)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FlexibleSpaceBar title is misaligned without the leading widget Invisible SliverAppBar title in Material 3 light theme

3 participants