Skip to content

Commit 74be14e

Browse files
committed
Improved Example Application
Former-commit-id: 50b68bb0eb2531cfc0a7c0a8f6c5771e32e49bf1 [formerly d9a02fd] Former-commit-id: fa7dde0ef5fd5b45391fce2ccd81452b89056333
1 parent 907cb90 commit 74be14e

File tree

3 files changed

+98
-35
lines changed

3 files changed

+98
-35
lines changed

example/lib/screens/main/main.dart

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class MainScreen extends StatefulWidget {
1919
}
2020

2121
class _MainScreenState extends State<MainScreen> {
22-
int _currentPageIndex = 0;
22+
static const Color backgroundColor = Color(0xFFeaf6f5);
2323
late final PageController _pageController;
24+
int _currentPageIndex = 0;
25+
bool extended = false;
2426

25-
List<Widget> get _destinations => [
27+
List<NavigationDestination> get _destinations => [
2628
const NavigationDestination(
2729
icon: Icon(Icons.map),
2830
label: 'Map',
@@ -52,14 +54,8 @@ class _MainScreenState extends State<MainScreen> {
5254
),
5355
label: 'Recover',
5456
),
55-
NavigationDestination(
56-
icon: Row(
57-
mainAxisSize: MainAxisSize.min,
58-
children: const [
59-
Icon(Icons.settings),
60-
Icon(Icons.info),
61-
],
62-
),
57+
const NavigationDestination(
58+
icon: Icon(Icons.settings),
6359
label: 'Settings',
6460
),
6561
];
@@ -100,19 +96,74 @@ class _MainScreenState extends State<MainScreen> {
10096
@override
10197
Widget build(BuildContext context) => FMTCBackgroundDownload(
10298
child: Scaffold(
103-
backgroundColor: Colors.white,
104-
bottomNavigationBar: NavigationBar(
105-
onDestinationSelected: _onDestinationSelected,
106-
selectedIndex: _currentPageIndex,
107-
destinations: _destinations,
108-
labelBehavior: MediaQuery.of(context).size.width > 450
109-
? null
110-
: NavigationDestinationLabelBehavior.onlyShowSelected,
111-
),
112-
body: PageView(
113-
controller: _pageController,
114-
physics: const NeverScrollableScrollPhysics(),
115-
children: _pages,
99+
backgroundColor: backgroundColor,
100+
bottomNavigationBar: MediaQuery.of(context).size.width > 950
101+
? null
102+
: NavigationBar(
103+
backgroundColor:
104+
Theme.of(context).navigationBarTheme.backgroundColor,
105+
onDestinationSelected: _onDestinationSelected,
106+
selectedIndex: _currentPageIndex,
107+
destinations: _destinations,
108+
labelBehavior: MediaQuery.of(context).size.width > 450
109+
? null
110+
: NavigationDestinationLabelBehavior.onlyShowSelected,
111+
),
112+
body: Row(
113+
children: [
114+
if (MediaQuery.of(context).size.width > 950)
115+
NavigationRail(
116+
onDestinationSelected: _onDestinationSelected,
117+
selectedIndex: _currentPageIndex,
118+
groupAlignment: 0,
119+
extended: extended,
120+
backgroundColor: backgroundColor,
121+
destinations: _destinations
122+
.map(
123+
(d) => NavigationRailDestination(
124+
icon: d.icon,
125+
label: Text(d.label),
126+
padding: const EdgeInsets.all(10),
127+
),
128+
)
129+
.toList(),
130+
leading: Row(
131+
children: [
132+
AnimatedContainer(
133+
width: extended ? 205 : 0,
134+
duration: kThemeAnimationDuration,
135+
curve: Curves.easeInOut,
136+
),
137+
IconButton(
138+
icon: AnimatedSwitcher(
139+
duration: kThemeAnimationDuration,
140+
switchInCurve: Curves.easeInOut,
141+
switchOutCurve: Curves.easeInOut,
142+
child: Icon(
143+
extended ? Icons.menu_open : Icons.menu,
144+
key: UniqueKey(),
145+
),
146+
),
147+
onPressed: () => setState(() => extended = !extended),
148+
tooltip: !extended ? 'Extend Menu' : 'Collapse Menu',
149+
),
150+
],
151+
),
152+
),
153+
Expanded(
154+
child: ClipRRect(
155+
borderRadius: const BorderRadius.only(
156+
topLeft: Radius.circular(16),
157+
bottomLeft: Radius.circular(16),
158+
),
159+
child: PageView(
160+
controller: _pageController,
161+
physics: const NeverScrollableScrollPhysics(),
162+
children: _pages,
163+
),
164+
),
165+
),
166+
],
116167
),
117168
),
118169
);

example/lib/screens/main/pages/stores/components/store_tile.dart

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ class _StoreTileState extends State<StoreTile> {
3434

3535
late final _store = FMTC.instance(widget.storeName);
3636

37-
void _loadStatistics() {
38-
_tiles = _store.stats.storeLengthAsync.then((l) => l.toString());
39-
_size = _store.stats.storeSizeAsync.then((s) => (s * 1024).asReadableSize);
40-
_cacheHits = _store.stats.cacheHitsAsync.then((h) => h.toString());
41-
_cacheMisses = _store.stats.cacheMissesAsync.then((m) => m.toString());
37+
void _loadStatistics({bool withoutCachedStatistics = false}) {
38+
final stats =
39+
!withoutCachedStatistics ? _store.stats : _store.stats.noCache;
40+
41+
_tiles = stats.storeLengthAsync.then((l) => l.toString());
42+
_size = stats.storeSizeAsync.then((s) => (s * 1024).asReadableSize);
43+
_cacheHits = stats.cacheHitsAsync.then((h) => h.toString());
44+
_cacheMisses = stats.cacheMissesAsync.then((m) => m.toString());
4245
_image = _store.manage.tileImageAsync(randomRange: 20, size: 125);
4346

4447
setState(() {});
@@ -48,28 +51,36 @@ class _StoreTileState extends State<StoreTile> {
4851
FutureBuilder<String>(
4952
future: _tiles,
5053
builder: (context, snapshot) => StatDisplay(
51-
statistic: snapshot.data,
54+
statistic: snapshot.connectionState != ConnectionState.done
55+
? null
56+
: snapshot.data,
5257
description: 'Total Tiles',
5358
),
5459
),
5560
FutureBuilder<String>(
5661
future: _size,
5762
builder: (context, snapshot) => StatDisplay(
58-
statistic: snapshot.data,
63+
statistic: snapshot.connectionState != ConnectionState.done
64+
? null
65+
: snapshot.data,
5966
description: 'Total Size',
6067
),
6168
),
6269
FutureBuilder<String>(
6370
future: _cacheHits,
6471
builder: (context, snapshot) => StatDisplay(
65-
statistic: snapshot.data,
72+
statistic: snapshot.connectionState != ConnectionState.done
73+
? null
74+
: snapshot.data,
6675
description: 'Cache Hits',
6776
),
6877
),
6978
FutureBuilder<String>(
7079
future: _cacheMisses,
7180
builder: (context, snapshot) => StatDisplay(
72-
statistic: snapshot.data,
81+
statistic: snapshot.connectionState != ConnectionState.done
82+
? null
83+
: snapshot.data,
7384
description: 'Cache Misses',
7485
),
7586
),
@@ -214,8 +225,9 @@ class _StoreTileState extends State<StoreTile> {
214225
),
215226
IconButton(
216227
icon: const Icon(Icons.refresh),
217-
tooltip: 'Refresh Statistics',
218-
onPressed: _loadStatistics,
228+
tooltip: 'Force Refresh Statistics',
229+
onPressed: () =>
230+
_loadStatistics(withoutCachedStatistics: true),
219231
),
220232
IconButton(
221233
icon: Icon(

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: The example application for 'flutter_map_tile_caching', showcasing
33
it's functionality and use-cases.
44
publish_to: "none"
55

6-
version: 5.1.0
6+
version: 5.1.0+1
77

88
environment:
99
sdk: ">=2.15.0 <3.0.0"

0 commit comments

Comments
 (0)