Skip to content

Instantly share code, notes, and snippets.

@fabiomsr
Last active January 2, 2019 12:52
Show Gist options
  • Save fabiomsr/706f381f6aab59b3e5f741b8f66abf84 to your computer and use it in GitHub Desktop.
Save fabiomsr/706f381f6aab59b3e5f741b8f66abf84 to your computer and use it in GitHub Desktop.
Flutter flexible app bar
import 'package:flutter/material.dart';
class FlexibleAppBar extends SliverAppBar {
static const double height = 256.0;
FlexibleAppBar(String title, String imageUrl) : super(
pinned: true,
expandedHeight: height,
flexibleSpace: FlexibleSpaceBar(
title: Text(title),
background: _buildBackground(imageUrl)
)
);
static Widget _buildBackground(String imageUrl) {
return Stack (
fit: StackFit.expand,
children: <Widget>[
Image.network(
imageUrl,
fit: BoxFit.cover,
height: height
),
DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: FractionalOffset(0.5, 0.6),
end: FractionalOffset(0.5, 1.0),
colors: <Color>[Color(0x00000000), Color(0x70000000)]
)
)
)
]
);
}
}
@ihsanberahim
Copy link

thank you for this example. Now, i know how to create template that can be used into another screens.

@gmaggio
Copy link

gmaggio commented Oct 11, 2018

I get an error: The named parameter 'expandedHeight' isn't defined. Do you know why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment