background_app_bar 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

Widget Background App Bar #

A background app bar plugin, use this plugin if you want to preserve background of sliver app bar when scrolling,

inspired by GradientAppBar GitHub

Screenshots #

Don't forget to tap + button 5 times

Screenshot-1565398534.png Screenshot-1569417041.png Screenshot-1569417048.png Screenshot-1569417051.png

Getting Started #

  1. Depend on it by adding this to your pubspec.yaml file: background_app_bar: ^1.0.0

  2. Import it: import 'package:background_app_bar/background_app_bar.dart'

  3. Replace your current FlexibleSpaceBar (In the AppBar or SliverAppBar) to BackgroundFlexibleSpaceBar.

new SliverAppBar(
    expandedHeight: _APP_BAR_SIZE,
    floating: false,
    pinned: true,
    snap: false,
    elevation: 0.0,
    backgroundColor: Colors.transparent,
    flexibleSpace: new BackgroundFlexibleSpaceBar(
        title: new Text( widget.title ),
        centerTitle: false,
        titlePadding: const EdgeInsets.only(left: 20.0, bottom: 20.0),
        background: new ClipRect(
            child: new Container(
                child: new BackdropFilter(
                    filter: new ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
                    child: new Container(
                        decoration: new BoxDecoration(
                            color: Colors.black.withOpacity(0.5),
                        ),
                    ),
                ),
                decoration: new BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage(
                            "images/bg.jpg",
                        ),
                        fit: BoxFit.fitWidth
					)
				),
			),
		),
	),
)

[0.0.1] - 10 August 2019

  • Initial Commit

[1.0.0] - 25 September 2019

  • Breaking Change #

    remove BackgroundAppBar has been remove, use AppBar instead, for same effect see example.
    remove SliverBackgroundAppBar has been remove, use SliverAppBar instead, for same effect see example.

  • add BackgroundFlexibleSpaceBar Widget

[1.0.1] - 27 September 2019

  • fix documentation

example/lib/example.dart

import 'dart:ui';

import 'package:background_app_bar/background_app_bar.dart';
import 'package:flutter/material.dart';

const _APP_BAR_SIZE = 250.0;

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
	const MyApp();
	@override Widget build(BuildContext context) => new MaterialApp(
		title: 'Flutter Demo',
		theme: new ThemeData(
			primarySwatch: Colors.blue,
		),
		home: new MyHomePage(title: 'Flutter Demo Home Page'),
	);
}

class MyHomePageSliver extends StatefulWidget {
	MyHomePageSliver({Key key, this.title, this.counter}) : super(key: key);
	final String title;
	final int counter;
	@override State<StatefulWidget> createState() => new _MyHomePageSliverState();
}

class _MyHomePageSliverState extends State<MyHomePageSliver> {
	
	int _counter = 0;
	
	@override Widget build(BuildContext context) => new Scaffold(
		body: new NestedScrollView(
			headerSliverBuilder: ( _, __ ) => <Widget>[
				new SliverAppBar(
					expandedHeight: _APP_BAR_SIZE,
					floating: false,
					pinned: true,
					snap: false,
					elevation: 0.0,
					backgroundColor: Colors.transparent,
					flexibleSpace: new BackgroundFlexibleSpaceBar(
						title: new Text( widget.title ),
						centerTitle: false,
						titlePadding: const EdgeInsets.only(left: 20.0, bottom: 20.0),
						background: new ClipRect(
							child: new Container(
								child: new BackdropFilter(
									filter: new ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
									child: new Container(
										decoration: new BoxDecoration(
											color: Colors.black.withOpacity(0.5),
										),
									),
								),
								decoration: new BoxDecoration(
									image: new DecorationImage(
										image: new AssetImage(
											"images/bg.jpg",
										),
										fit: BoxFit.fitWidth
									)
								),
							),
						),
					),
				),
			],
			body: new Center(
				child: new Column(
					mainAxisAlignment: MainAxisAlignment.center,
					children: <Widget>[
						new Text(
							"Photo by Matt Artz on Unsplash",
						),
						new Text(
							"You have pushed the button this many times:",
						),
						new Text(
							'$_counter',
							style: Theme.of(context).textTheme.display1,
						),
					],
				),
			),
		),
		floatingActionButton: new FloatingActionButton(
			onPressed: _incrementCounter,
			tooltip: 'Increment',
			child: new Icon(Icons.add),
		),
	);
	
	@override
	void initState() {
		_counter = widget.counter ?? 0;
		super.initState();
	}
	
	void _incrementCounter() {
		setState(() {
			_counter++;
		});
		if ( _counter % 7 == 0 ) {
			Navigator.of(context).pushReplacement(
				new MaterialPageRoute(
					builder: ( _ ) => new MyHomePage(
						title: widget.title,
						counter: _counter,
					),
				)
			);
		}
	}
}

class MyHomePage extends StatefulWidget {
	MyHomePage({Key key, this.title, this.counter}) : super(key: key);
	final String title;
	final int counter;
	@override _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
	int _counter = 0;
	
	@override
	void initState() {
		_counter = widget.counter ?? 0;
		super.initState();
	}
	
	void _incrementCounter() {
		setState(() {
			_counter++;
		});
		if ( _counter % 5 == 0 ) {
			Navigator.of(context).pushReplacement(
				new MaterialPageRoute(
					builder: ( _ ) => new MyHomePageSliver(
						title: widget.title,
						counter: _counter,
					),
				)
			);
		}
	}
	
	@override
	Widget build(BuildContext context) {
		return new Scaffold(
			appBar: new AppBar(
				title: new Text(widget.title),
				flexibleSpace: new ClipRect(
					child: new Container(
						child: new BackdropFilter(
							filter: new ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
							child: new Container(
								decoration: new BoxDecoration(
									color: Colors.black.withOpacity(0.5),
								),
							),
						),
						decoration: new BoxDecoration(
							image: new DecorationImage(
								image: new AssetImage(
									"images/bg.jpg",
								),
								fit: BoxFit.fitWidth
							)
						),
					),
				),
			),
			body: new Center(
				child: new Column(
					mainAxisAlignment: MainAxisAlignment.center,
					children: <Widget>[
						new Text(
							"Photo by Matt Artz on Unsplash",
						),
						new Text(
							"You have pushed the button this many times:",
						),
						new Text(
							'$_counter',
							style: Theme.of(context).textTheme.display1,
						),
					],
				),
			),
			floatingActionButton: new FloatingActionButton(
				onPressed: _incrementCounter,
				tooltip: 'Increment',
				child: new Icon(Icons.add),
			),
		);
	}
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  background_app_bar: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:background_app_bar/background_app_bar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/background_app_bar.dart.

Run flutter format to format lib/background_app_bar.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test