Skip to content

Using a Row in FlexibleSpaceBar inside a SliverAppBar #11954

Closed

Description

@balazsgerlei

Somewhat related to my other issue (#11951), I would like to use a Row as the "title" Widget of a FlexibleSpaceBar inside a SliverAppBar. I would like to have an Image and a Text inside this row (with some padding), but if I do that, it won't animate correctly when scrolling. On iOS, it completely breaks the animation, on Android, it positions the Row incorrectly when collapsed to normal Toolbar height. I can see that it tries to maintain the same bottom padding which is ideal for a single Text (I understand that it was intentionally to optimize for a Text) but not looks good when something larger is contained.

I think that having a parameter to set the bottom padding which is applied to the Widget that is supplied as the title would enable more creative designs, including the one I would like to achieve. As far as I know I could not make it work even if I subclass the SliverAppBar as it uses private classes inside.

Please let me know if the thing that I described is possible (and how), or if you may implement something I asked in the future.

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on May 18, 2018
  2. added this to the milestone on May 18, 2018
  3. Hixie commented on May 18, 2018

    @Hixie
    Contributor

    Do you have a sample main.dart showing what you mean so we can play with it?

  4. Hixie commented on May 18, 2018

    @Hixie
    Contributor
  5. modified the milestones: , on Jan 7, 2020
  6. TahaTesser commented on Mar 24, 2020

    @TahaTesser
    Contributor

    Hi @balazsgerlei

    Please checkout this sample

    Code Sample

    // Flutter code sample for FlexibleSpaceBar
    
    // This sample application demonstrates the different features of the
    // [FlexibleSpaceBar] when used in a [SliverAppBar]. This app bar is configured
    // to stretch into the overscroll space, and uses the
    // [FlexibleSpaceBar.stretchModes] to apply `fadeTitle`, `blurBackground` and
    // `zoomBackground`. The app bar also makes use of [CollapseMode.parallax] by
    // default.
    
    import 'package:flutter/material.dart';
    
    void main() => runApp(MaterialApp(home: MyApp()));
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: CustomScrollView(
            physics: const BouncingScrollPhysics(),
            slivers: <Widget>[
              SliverAppBar(
                stretch: true,
                onStretchTrigger: () {
                  // Function callback for stretch
                  return;
                },
                expandedHeight: 300.0,
                flexibleSpace: FlexibleSpaceBar(
                  stretchModes: <StretchMode>[
                    StretchMode.zoomBackground,
                    StretchMode.blurBackground,
                    StretchMode.fadeTitle,
                  ],
                  centerTitle: true,
                  title: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text('Flight Report'),
                      Image.network(
                          'https://www.freeiconspng.com/uploads/camera-icon-png--clipart-best-23.png',
                          height: 50,
                          width: 50)
                    ],
                  ),
                  background: Stack(
                    fit: StackFit.expand,
                    children: [
                      Image.network(
                        'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg',
                        fit: BoxFit.cover,
                      ),
                      const DecoratedBox(
                        decoration: BoxDecoration(
                          gradient: LinearGradient(
                            begin: Alignment(0.0, 0.5),
                            end: Alignment(0.0, 0.0),
                            colors: <Color>[
                              Color(0x60000000),
                              Color(0x00000000),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              SliverList(
                delegate: SliverChildListDelegate([
                  ListTile(
                    leading: Icon(Icons.wb_sunny),
                    title: Text('Sunday'),
                    subtitle: Text('sunny, h: 80, l: 65'),
                  ),
                  ListTile(
                    leading: Icon(Icons.wb_sunny),
                    title: Text('Monday'),
                    subtitle: Text('sunny, h: 80, l: 65'),
                  ),
                  // ListTiles++
                ]),
              ),
            ],
          ),
        );
      }
    }
    

    We can use row in title
    if you disagree please write in the comments and I will reopen it
    Thank you

  7. yassine12you commented on Apr 23, 2020

    @yassine12you

    you must center your row
    child: Row(
    mainAxisAlignment: MainAxisAlignment.center,

    Best regards

  8. github-actions commented on Aug 17, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions