From 8182c1a5220072d6bbe9c34d0a8f71a0c66c23bb Mon Sep 17 00:00:00 2001 From: Alabhya Date: Sat, 12 Dec 2020 03:13:05 +0530 Subject: [PATCH] Added dartpad examples for SliverAppBar (#69781) --- .../flutter/lib/src/material/app_bar.dart | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index e61b39b0fb..35154cde11 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -1262,6 +1262,118 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { /// ``` /// {@end-tool} /// +/// {@tool dartpad --template=freeform} +/// +/// This sample shows a [SliverAppBar] and it's behaviors when using the [pinned], [snap] and [floating] parameters. +/// +/// ```dart imports +/// import 'package:flutter/material.dart'; +/// ``` +/// +/// ```dart +/// void main() => runApp(MyApp()); +/// +/// class MyApp extends StatefulWidget { +/// const MyApp({Key key}) : super(key: key); +/// +/// @override +/// State createState() => _MyAppState(); +/// } +/// +/// class _MyAppState extends State { +/// bool _pinned = true; +/// bool _snap = false; +/// bool _floating = false; +/// +/// // SliverAppBar is declared in Scaffold.body, in slivers of a +/// // CustomScrollView. +/// @override +/// Widget build(BuildContext context) { +/// return MaterialApp( +/// home: Scaffold( +/// body: CustomScrollView( +/// slivers: [ +/// SliverAppBar( +/// pinned: this._pinned, +/// snap: this._snap, +/// floating: this._floating, +/// expandedHeight: 160.0, +/// flexibleSpace: FlexibleSpaceBar( +/// title: const Text("SliverAppBar"), +/// background: FlutterLogo(), +/// ), +/// ), +/// SliverToBoxAdapter( +/// child: Center( +/// child: Container( +/// height: 2000, +/// child: const Text("Scroll to see SliverAppBar in effect ."), +/// ), +/// ), +/// ), +/// ], +/// ), +/// bottomNavigationBar: BottomAppBar( +/// child: ButtonBar( +/// alignment: MainAxisAlignment.spaceEvenly, +/// children: [ +/// Row( +/// children: [ +/// const Text('pinned'), +/// Switch( +/// onChanged: (bool val) { +/// setState(() { +/// this._pinned = val; +/// }); +/// }, +/// value: this._pinned, +/// ), +/// ], +/// ), +/// Row( +/// children: [ +/// const Text('snap'), +/// Switch( +/// onChanged: (bool val) { +/// setState(() { +/// this._snap = val; +/// //Snapping only applies when the app bar is floating. +/// this._floating = this._floating || val; +/// }); +/// }, +/// value: this._snap, +/// ), +/// ], +/// ), +/// Row( +/// children: [ +/// const Text('floating'), +/// Switch( +/// onChanged: (bool val) { +/// setState(() { +/// this._floating = val; +/// if (this._snap == true) { +/// if (this._floating != true) { +/// this._snap = false; +/// } +/// } +/// }); +/// }, +/// value: this._floating, +/// ), +/// ], +/// ), +/// ], +/// ), +/// ), +/// ), +/// ); +/// } +/// } +/// +/// ``` +/// {@end-tool} +/// /// ## Animated Examples /// /// The following animations show how app bars with different configurations