Skip to content

Commit e48c83b

Browse files
authored
Merge pull request #73 from mockturtl/feat-70-vary-front-height
feat: variable front page height
2 parents ce3116b + 6cdd29d commit e48c83b

File tree

4 files changed

+224
-84
lines changed

4 files changed

+224
-84
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [0.5.0]
2+
3+
* **BREAKING**: requires Dart >= 2.3
4+
* `BackdropScaffold`: added `frontLayerActiveFactor` [#73][]
5+
6+
[#73]: https://github.com/fluttercommunity/backdrop/pull/73
7+
18
## [0.4.7] - 28 October 2020
29

310
* `BackdropScaffold`: added `scaffoldKey` [https://github.com/fluttercommunity/backdrop/pull/64]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import 'package:backdrop/backdrop.dart';
2+
import 'package:flutter/material.dart';
3+
4+
void main() => runApp(MyApp());
5+
6+
/// Showcase for a Material Backdrop acting as a menu.
7+
class MyApp extends StatefulWidget {
8+
@override
9+
_MyAppState createState() => _MyAppState();
10+
}
11+
12+
class _MyAppState extends State<MyApp> {
13+
int _currentIndex = 0;
14+
15+
final List<Widget> _pages = [
16+
_TallPage(),
17+
...List.generate(9, (i) => _ShortPage(i + 1)),
18+
];
19+
20+
final _nav = List.generate(
21+
10,
22+
(i) => ListTile(
23+
title: Text('Menu: open page #$i',
24+
style: TextStyle(color: Colors.white))));
25+
26+
double get _heightFactor => _currentIndex == 0 ? 1 : (.1 * _currentIndex);
27+
28+
@override
29+
Widget build(BuildContext context) => MaterialApp(
30+
title: 'Backdrop Demo',
31+
home: BackdropScaffold(
32+
appBar: BackdropAppBar(title: Text("AppBar is OK 👍")),
33+
frontLayer: _pages[_currentIndex],
34+
stickyFrontLayer: true,
35+
backLayerScrim: Colors.red.withOpacity(0.5),
36+
frontLayerScrim: Colors.green.withOpacity(0.5),
37+
frontLayerActiveFactor: _heightFactor,
38+
subHeader: BackdropSubHeader(title: Text('Subheader')),
39+
backLayer: BackdropNavigationBackLayer(
40+
items: _nav,
41+
onTap: (int position) =>
42+
{setState(() => _currentIndex = position)},
43+
separatorBuilder: (_, __) => _MyDivider())));
44+
}
45+
46+
class _MyDivider extends StatelessWidget {
47+
const _MyDivider();
48+
49+
@override
50+
Widget build(BuildContext context) =>
51+
Divider(indent: 16, endIndent: 16, color: Colors.white);
52+
}
53+
54+
/// When the front layer doesn't have much content, its height while revealed
55+
/// is configurable via [BackdropScaffold.frontLayerActiveFactor].
56+
class _ShortPage extends StatelessWidget {
57+
final int index;
58+
59+
_ShortPage(this.index);
60+
61+
@override
62+
Widget build(BuildContext context) => Center(
63+
child: Column(
64+
mainAxisSize: MainAxisSize.min,
65+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
66+
children: [
67+
Text("Page #$index is open with desired height."),
68+
const Flexible(child: FractionallySizedBox(heightFactor: 0.1)),
69+
Text("It looks better! 😄"),
70+
const Flexible(child: FractionallySizedBox(heightFactor: 0.1)),
71+
Text("But Page #0 still needs to be tall."),
72+
]));
73+
}
74+
75+
/// A front layer with a lot of content should reveal to show as much as possible.
76+
class _TallPage extends StatelessWidget {
77+
@override
78+
Widget build(BuildContext context) => ListView(
79+
children: List.generate(
80+
20,
81+
(index) => Padding(
82+
padding: const EdgeInsets.all(16),
83+
child: Text("Tall page #0, lots of content 👍"))));
84+
}

0 commit comments

Comments
 (0)