Reputation: 107
I am trying to make an app bar looks like this:
I hope to collapse the big image using SilverAppBar
, but I am having hard time to insert AssetImage
(or Image.asset'). I almost exactly followed the code from the [official Flutter website][2], and unfortunately, both
AssetImageand
Image.asset` cannot be used as shown below:
Is there any way to do this?
Upvotes: 0
Views: 319
Reputation: 121
Please add background_app_bar: ^1.0.0 dependency.
import 'package:background_app_bar/background_app_bar.dart';
...
SliverAppBar(
backgroundColor: Colors.white,
pinned: true,
snap: true,
floating: true,
expandedHeight: 160.0,
flexibleSpace: new BackgroundFlexibleSpaceBar( // Add this
title: new Text('title'),
centerTitle: false,
titlePadding: const EdgeInsets.only(left: 5.0, bottom: 5.0),
background: Image.asset('url'),
),
),
Upvotes: 0
Reputation: 1369
maybe you can use background like this:
SliverAppBar(
...
...
background: Image(
image: NetworkImage(recipeDetails.coverPhoto),
fit: BoxFit.cover,
),
),
Upvotes: 1
Reputation: 67
Wrap Image.asset with Container widget
Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
child: Image.asset('name'),
)
],
),
Upvotes: 1