Skip to content

Commit

Permalink
#refactor use MyRoute2 for Appbar examples
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Wei committed Jul 27, 2019
1 parent 9f02fba commit 9b266e4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 107 deletions.
59 changes: 51 additions & 8 deletions lib/my_app_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ const kMyAppRoutesStructure = <MyRouteGroup>[
title: 'DataTable',
description: 'Showing data in a table.',
links: {
'Docs':
'https://docs.flutter.io/flutter/material/PaginatedDataTable-class.html'
},
'Docs':
'https://docs.flutter.io/flutter/material/PaginatedDataTable-class.html'
},
),
],
),
Expand All @@ -303,11 +303,54 @@ const kMyAppRoutesStructure = <MyRouteGroup>[
quarterTurns: 2,
),
routes: <MyRoute>[
BasicAppbarExample(),
BottomAppbarExample(),
SliverAppBarExample(),
AppbarSearchExample(),
BackdropExample(),
MyRoute2(
child: BasicAppbarExample(),
sourceFilePath: 'lib/routes/appbar_basic_appbar_ex.dart',
title: 'Basic AppBar',
links: {
'Doc': 'https://docs.flutter.io/flutter/material/AppBar-class.html',
},
),
MyRoute2(
child: BottomAppbarExample(),
sourceFilePath: 'lib/routes/appbar_bottom_appbar_ex.dart',
title: 'Bottom AppBar',
links: {
'Doc':
'https://docs.flutter.io/flutter/material/BottomNavigationBar-class.html'
},
),
MyRoute2(
child: SliverAppBarExample(),
sourceFilePath: 'lib/routes/appbar_sliver_appbar_ex.dart',
title: 'Sliver AppBar',
description: 'Appbar that auto-hides.',
links: {
'Doc':
'https://docs.flutter.io/flutter/material/SliverAppBar-class.html',
'Medium article':
'https://flutterdoc.com/animating-app-bars-in-flutter-cf034cd6c68b',
},
),
MyRoute2(
child: AppBarSearchExample(),
sourceFilePath: 'lib/routes/appbar_search_ex.dart',
title: 'Search',
links: {
'Doc':
'https://docs.flutter.io/flutter/material/SearchDelegate-class.html'
},
),
MyRoute2(
child: BackdropExample(),
sourceFilePath: 'lib/routes/appbar_backdrop_ex.dart',
title: 'Backdrop',
description: 'Switching between front and back layer.',
links: {
'Medium article':
'https://medium.com/flutter/decomposing-widgets-backdrop-b5c664fb9cf4'
},
),
],
),
MyRouteGroup(
Expand Down
21 changes: 3 additions & 18 deletions lib/routes/appbar_backdrop_ex.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import 'package:backdrop/backdrop.dart';
import 'package:flutter/material.dart';
import '../my_route.dart';

class BackdropExample extends MyRoute {
const BackdropExample(
[String sourceFile = 'lib/routes/appbar_backdrop_ex.dart'])
: super(sourceFile);
class BackdropExample extends StatelessWidget {
const BackdropExample({Key key}) : super(key: key);

@override
get title => 'Backdrop';

@override
get description => 'Switching between front and back layer.';

@override
get links => {
'Medium article':
'https://medium.com/flutter/decomposing-widgets-backdrop-b5c664fb9cf4'
};

@override
Widget buildMyRouteContent(BuildContext context) {
Widget build(BuildContext context) {
return BackdropScaffold(
title: Text('Backdrop demo'),
iconPosition: BackdropIconPosition.action,
Expand Down
17 changes: 3 additions & 14 deletions lib/routes/appbar_basic_appbar_ex.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import 'package:flutter/material.dart';
import '../my_route.dart';

class BasicAppbarExample extends MyRoute {
const BasicAppbarExample(
[String sourceFile = 'lib/routes/appbar_basic_appbar_ex.dart'])
: super(sourceFile);
class BasicAppbarExample extends StatelessWidget {
const BasicAppbarExample({Key key}) : super(key: key);

@override
get title => 'Basic AppBar';

@override
get links => {
'Doc': 'https://docs.flutter.io/flutter/material/AppBar-class.html',
};

@override
Widget buildMyRouteContent(BuildContext context) {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.redAccent,
Expand Down
17 changes: 3 additions & 14 deletions lib/routes/appbar_bottom_appbar_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@ import '../my_route.dart';

// Adapted from offical flutter gallery:
// https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart
class BottomAppbarExample extends MyRoute {
const BottomAppbarExample(
[String sourceFile = 'lib/routes/appbar_bottom_appbar_ex.dart'])
: super(sourceFile);
class BottomAppbarExample extends StatelessWidget {
const BottomAppbarExample({Key key}) : super(key: key);

@override
get title => 'Bottom AppBar';

@override
get links => {
'Doc':
'https://docs.flutter.io/flutter/material/BottomNavigationBar-class.html'
};

@override
Widget buildMyRouteContent(BuildContext context) {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Bottom appbar demo'),
Expand Down
31 changes: 6 additions & 25 deletions lib/routes/appbar_search_ex.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
import 'package:flutter/material.dart';
import '../my_route.dart';
import 'package:english_words/english_words.dart' as english_words;

class AppbarSearchExample extends MyRoute {
const AppbarSearchExample(
[String sourceFile = 'lib/routes/appbar_search_ex.dart'])
: super(sourceFile);

@override
get title => 'Search';

@override
get links => {
'Doc':
'https://docs.flutter.io/flutter/material/SearchDelegate-class.html'
};

@override
Widget buildMyRouteContent(BuildContext context) {
return _AppbarSearchDemo();
}
}

// Adapted from search demo in offical flutter gallery:
// https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/search_demo.dart
class _AppbarSearchDemo extends StatefulWidget {
class AppBarSearchExample extends StatefulWidget {
const AppBarSearchExample({Key key}) : super(key: key);

@override
_AppbarSearchDemoState createState() => _AppbarSearchDemoState();
_AppBarSearchExampleState createState() => _AppBarSearchExampleState();
}

class _AppbarSearchDemoState extends State<_AppbarSearchDemo> {
class _AppBarSearchExampleState extends State<AppBarSearchExample> {
final List<String> kEnglishWords;
_MySearchDelegate _delegate;

_AppbarSearchDemoState()
_AppBarSearchExampleState()
: kEnglishWords = List.from(Set.from(english_words.all))
..sort(
(w1, w2) => w1.toLowerCase().compareTo(w2.toLowerCase()),
Expand Down
32 changes: 4 additions & 28 deletions lib/routes/appbar_sliver_appbar_ex.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
import 'package:flutter/material.dart';
import '../my_route.dart';

// Adapted from offical flutter gallery:
// https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart
class SliverAppBarExample extends MyRoute {
const SliverAppBarExample(
[String sourceFile = 'lib/routes/appbar_sliver_appbar_ex.dart'])
: super(sourceFile);
class SliverAppBarExample extends StatefulWidget {
const SliverAppBarExample({Key key}) : super(key: key);

@override
get title => 'Sliver AppBar';

@override
get description => 'Appbar that auto-hides.';

@override
get links => {
'Doc':
'https://docs.flutter.io/flutter/material/SliverAppBar-class.html',
'Medium article':
'https://flutterdoc.com/animating-app-bars-in-flutter-cf034cd6c68b',
};

@override
Widget buildMyRouteContent(BuildContext context) {
return _SliverAppbarPage();
}
}

class _SliverAppbarPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _SliverAppbarPageState();
State<StatefulWidget> createState() => _SliverAppBarExampleState();
}

class _SliverAppbarPageState extends State<_SliverAppbarPage> {
class _SliverAppBarExampleState extends State<SliverAppBarExample> {
bool _pinned = true;
bool _snap = false;
bool _floating = false;
Expand Down

0 comments on commit 9b266e4

Please sign in to comment.