Skip to content

Conversation

@TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Aug 15, 2023

fixes Long FlexibleSpaceBar.title doesn't respect the leading widget

Description

  • This adds FlexibleSpaceBarSettings.hasLeading for the FlexibleSpaceBar's title to respect the leading widget.
  • Use the new FlexibleSpaceBarSettings.hasLeading property in the SliverAppBar for its FlexibleSpaceBar.

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 MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: const Example(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const Text('TargetPlatform.Android'),
          Theme(
            data: Theme.of(context).copyWith(
              platform: TargetPlatform.android,
            ),
            child: Container(
              height: 250,
              padding: const EdgeInsets.all(8),
              decoration: BoxDecoration(
                border: Border.all(
                  color: Colors.amber,
                  width: 4,
                ),
              ),
              child: const AppBarLeading(
                showLeading: true,
                showTitle: false,
              ),
            ),
          ),
          const Text('TargetPlatform.iOS'),
          Theme(
            data: Theme.of(context).copyWith(
              platform: TargetPlatform.iOS,
            ),
            child: Container(
              height: 250,
              padding: const EdgeInsets.all(8),
              decoration: BoxDecoration(
                border: Border.all(
                  color: Colors.amber,
                  width: 2,
                ),
              ),
              child: const AppBarLeading(
                showLeading: true,
                showTitle: false,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class AppBarLeading extends StatelessWidget {
  const AppBarLeading({
    super.key,
    required this.showLeading,
    required this.showTitle,
  });

  final bool showLeading;
  final bool showTitle;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: const Drawer(),
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            automaticallyImplyLeading: showLeading,
            iconTheme: const IconThemeData(
              color: Colors.amber,
            ),
            title: showTitle ? const Text('AppBar') : null,
            flexibleSpace: FlexibleSpaceBar(
              title: Text('Title ' * 15),
              // centerTitle: true,
            ),
            toolbarHeight: showTitle ? 170 : 100,
          ),
        ],
      ),
    );
  }
}

Before

Screenshot 2023-08-15 at 18 11 34

After

Screenshot 2023-08-15 at 18 11 45

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 Aug 15, 2023
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 22, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 22, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 22, 2023

auto label is removed for flutter/flutter/132573, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@TahaTesser TahaTesser force-pushed the flexible_space_bar_leading branch from 4c8a3fe to 8bd7eb9 Compare August 22, 2023 16:23
@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 22, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 22, 2023

auto label is removed for flutter/flutter/132573, due to - The status or check suite Linux build_tests_1_3 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 22, 2023
@TahaTesser TahaTesser added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 22, 2023
@auto-submit auto-submit bot merged commit db89df5 into flutter:master Aug 22, 2023
@TahaTesser TahaTesser deleted the flexible_space_bar_leading branch August 22, 2023 20:47
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 23, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 23, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 23, 2023
flutter/flutter@54c98d7...bd836cc

2023-08-23 [email protected] Roll Packages from c730a90 to 3060b1a (4 revisions) (flutter/flutter#133149)
2023-08-23 [email protected] Roll Flutter Engine from 7d56840865d2 to 72a06427bd37 (8 revisions) (flutter/flutter#133139)
2023-08-23 [email protected] Manual roll Flutter Engine from b190f9015049 to 7d56840865d2 (15 revisions) (flutter/flutter#133106)
2023-08-23 [email protected] Reference AppLifecycleListener from widgets library (flutter/flutter#132995)
2023-08-23 [email protected] Support disabling animations in the CLI (flutter/flutter#132239)
2023-08-23 [email protected] Don't run on Samsung S10, shift to Pixel 7 Pro (flutter/flutter#133085)
2023-08-23 [email protected] Add test to mark recording as leaking. (flutter/flutter#133073)
2023-08-22 [email protected] Revert "[gallery] roll gallery to  ecfb9e5352bd12032301b12b30d5853d83d89bda" (flutter/flutter#133095)
2023-08-22 [email protected] [gallery] roll gallery to  ecfb9e5352bd12032301b12b30d5853d83d89bda (flutter/flutter#133083)
2023-08-22 [email protected] Update default menu text styles for Material 3 (flutter/flutter#131930)
2023-08-22 [email protected] Roll Flutter Engine from 28b8bd5d5d91 to b190f9015049 (3 revisions) (flutter/flutter#133078)
2023-08-22 [email protected] Fix `FlexibleSpaceBar.title` doesn't respect the leading widget (flutter/flutter#132573)
2023-08-22 [email protected] Roll Flutter Engine from 21437d384b56 to 28b8bd5d5d91 (1 revision) (flutter/flutter#133075)
2023-08-22 [email protected] Roll Flutter Engine from 090754879679 to 21437d384b56 (1 revision) (flutter/flutter#133072)
2023-08-22 [email protected] Add support for `Future<List<int>?>` to `MatchesGoldenFile` (flutter/flutter#132965)
2023-08-22 [email protected] Roll Packages from e26f3b9 to c730a90 (3 revisions) (flutter/flutter#133067)
2023-08-22 [email protected] Roll Flutter Engine from ff375bf5d8eb to 090754879679 (1 revision) (flutter/flutter#133066)
2023-08-22 [email protected] Increase heap size for examples/flutter_view gradle build (flutter/flutter#133064)
2023-08-22 [email protected] Roll Flutter Engine from c5e0152b01f4 to ff375bf5d8eb (4 revisions) (flutter/flutter#133062)
2023-08-22 [email protected] Fix memory leak in Form (flutter/flutter#132987)
2023-08-22 [email protected] Re-enable Xcode Debug tests (flutter/flutter#132523)
2023-08-22 [email protected] Increase heap for gradle in examples/platform_view (flutter/flutter#133052)
2023-08-22 [email protected] Cover more tests with leak tracking. (flutter/flutter#132806)
2023-08-22 [email protected] Roll Flutter Engine from f5f099a4a5e3 to c5e0152b01f4 (4 revisions) (flutter/flutter#133049)

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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
XilaiZhang added a commit that referenced this pull request Aug 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 15, 2023
@FrankSandqvist
Copy link

FrankSandqvist commented Nov 29, 2023

I believe this is a regression, as now my FlexibleSpaceBar looks quite messed up. Is there a way to override this behavior? I suppose adding padding to the right of the text, though I believe most often people would like centered titles to be centered, as otherwise it looks quite off visually

Screenshot 2023-11-29 at 09 53 37

@TahaTesser
Copy link
Member Author

@FrankSandqvist
This is fixed #138611

@TahaTesser
Copy link
Member Author

I noticed this bug myself a couple of weeks ago #138608 and fixed it.

cc: @Piinks might worth CP.

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.

Long FlexibleSpaceBar.title doesn't respect the leading widget

4 participants