Last active
January 2, 2019 12:52
-
-
Save fabiomsr/706f381f6aab59b3e5f741b8f66abf84 to your computer and use it in GitHub Desktop.
Flutter flexible app bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | |
) | |
) | |
) | |
] | |
); | |
} | |
} |
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
thank you for this example. Now, i know how to create template that can be used into another screens.