Unverified Commit 95e2cbb1 authored by Anurag Roy's avatar Anurag Roy Committed by GitHub

[SliverAppBar] Improve dartpad sample in documentation (#78984)

parent 89f82ff4
...@@ -1264,115 +1264,107 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1264,115 +1264,107 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// {@tool dartpad --template=freeform} /// {@tool dartpad --template=stateful_widget_material}
/// /// This sample shows a [SliverAppBar] and it's behavior when using the
/// This sample shows a [SliverAppBar] and it's behaviors when using the [pinned], [snap] and [floating] parameters. /// [pinned], [snap] and [floating] parameters.
///
/// ```dart imports
/// import 'package:flutter/material.dart';
/// ```
/// ///
/// ```dart /// ```dart
/// void main() => runApp(const MyApp()); /// bool _pinned = true;
/// /// bool _snap = false;
/// class MyApp extends StatefulWidget { /// bool _floating = false;
/// const MyApp({Key? key}) : super(key: key);
/// ///
/// @override /// // [SliverAppBar]s are typically used in [CustomScrollView.slivers], which in
/// State<StatefulWidget> createState() => _MyAppState(); /// // turn can be placed in a [Scaffold.body].
/// } /// @override
/// /// Widget build(BuildContext context) {
/// class _MyAppState extends State<MyApp> { /// return Scaffold(
/// bool _pinned = true; /// body: CustomScrollView(
/// bool _snap = false; /// slivers: <Widget>[
/// bool _floating = false; /// SliverAppBar(
/// /// pinned: _pinned,
/// // SliverAppBar is declared in Scaffold.body, in slivers of a /// snap: _snap,
/// // CustomScrollView. /// floating: _floating,
/// @override /// expandedHeight: 160.0,
/// Widget build(BuildContext context) { /// flexibleSpace: const FlexibleSpaceBar(
/// return MaterialApp( /// title: Text('SliverAppBar'),
/// home: Scaffold( /// background: FlutterLogo(),
/// body: CustomScrollView( /// ),
/// slivers: <Widget>[ /// ),
/// SliverAppBar( /// const SliverToBoxAdapter(
/// pinned: _pinned, /// child: SizedBox(
/// snap: _snap, /// height: 20,
/// floating: _floating, /// child: Center(
/// expandedHeight: 160.0, /// child: const Text('Scroll to see the SliverAppBar in effect.'),
/// flexibleSpace: const FlexibleSpaceBar(
/// title: Text('SliverAppBar'),
/// background: FlutterLogo(),
/// ),
/// ),
/// const SliverToBoxAdapter(
/// child: Center(
/// child: SizedBox(
/// height: 2000,
/// child: const Text('Scroll to see SliverAppBar in effect .'),
/// ),
/// ),
/// ), /// ),
/// ], /// ),
/// ), /// ),
/// bottomNavigationBar: BottomAppBar( /// SliverList(
/// child: ButtonBar( /// delegate: SliverChildBuilderDelegate(
/// alignment: MainAxisAlignment.spaceEvenly, /// (BuildContext context, int index) {
/// return Container(
/// color: index.isOdd ? Colors.white : Colors.black12,
/// height: 100.0,
/// child: Center(
/// child: Text('$index', textScaleFactor: 5),
/// ),
/// );
/// },
/// childCount: 20,
/// ),
/// ),
/// ],
/// ),
/// bottomNavigationBar: BottomAppBar(
/// child: ButtonBar(
/// alignment: MainAxisAlignment.spaceEvenly,
/// children: <Widget>[
/// Row(
/// children: <Widget>[ /// children: <Widget>[
/// Row( /// const Text('pinned'),
/// children: <Widget>[ /// Switch(
/// const Text('pinned'), /// onChanged: (bool val) {
/// Switch( /// setState(() {
/// onChanged: (bool val) { /// _pinned = val;
/// setState(() { /// });
/// _pinned = val; /// },
/// }); /// value: _pinned,
/// },
/// value: _pinned,
/// ),
/// ],
/// ), /// ),
/// Row( /// ],
/// children: <Widget>[ /// ),
/// const Text('snap'), /// Row(
/// Switch( /// children: <Widget>[
/// onChanged: (bool val) { /// const Text('snap'),
/// setState(() { /// Switch(
/// _snap = val; /// onChanged: (bool val) {
/// //Snapping only applies when the app bar is floating. /// setState(() {
/// _floating = _floating || val; /// _snap = val;
/// }); /// // Snapping only applies when the app bar is floating.
/// }, /// _floating = _floating || _snap;
/// value: _snap, /// });
/// ), /// },
/// ], /// value: _snap,
/// ), /// ),
/// Row( /// ],
/// children: <Widget>[ /// ),
/// const Text('floating'), /// Row(
/// Switch( /// children: <Widget>[
/// onChanged: (bool val) { /// const Text('floating'),
/// setState(() { /// Switch(
/// _floating = val; /// onChanged: (bool val) {
/// if (_snap == true) { /// setState(() {
/// if (_floating != true) { /// _floating = val;
/// _snap = false; /// _snap = _snap && _floating;
/// } /// });
/// } /// },
/// }); /// value: _floating,
/// },
/// value: _floating,
/// ),
/// ],
/// ), /// ),
/// ], /// ],
/// ), /// ),
/// ), /// ],
/// ), /// ),
/// ); /// ),
/// } /// );
/// } /// }
///
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment