Skip to content

Commit

Permalink
Improved example application
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Dec 19, 2024
1 parent ac62961 commit c6925be
Show file tree
Hide file tree
Showing 19 changed files with 800 additions and 547 deletions.
89 changes: 89 additions & 0 deletions example/lib/src/screens/main/layouts/horizontal.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
part of '../main.dart';

class _HorizontalLayout extends StatelessWidget {
const _HorizontalLayout({
required DraggableScrollableController bottomSheetOuterController,
required this.mapMode,
required this.selectedTab,
}) : _bottomSheetOuterController = bottomSheetOuterController;

final DraggableScrollableController _bottomSheetOuterController;
final MapViewMode mapMode;
final int selectedTab;

@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
body: LayoutBuilder(
builder: (context, constraints) => Row(
children: [
NavigationRail(
backgroundColor: Colors.transparent,
destinations: [
const NavigationRailDestination(
icon: Icon(Icons.map_outlined),
selectedIcon: Icon(Icons.map),
label: Text('Map'),
),
NavigationRailDestination(
icon: Selector<DownloadingProvider, bool>(
selector: (context, provider) =>
provider.storeName != null,
builder: (context, isDownloading, child) =>
!isDownloading ? child! : Badge(child: child),
child: const Icon(Icons.download_outlined),
),
selectedIcon: const Icon(Icons.download),
label: const Text('Download'),
),
NavigationRailDestination(
icon: Selector<RecoverableRegionsProvider, int>(
selector: (context, provider) =>
provider.failedRegions.length,
builder: (context, count, child) => count == 0
? child!
: Badge.count(count: count, child: child),
child: const Icon(Icons.support_outlined),
),
selectedIcon: const Icon(Icons.support),
label: const Text('Recovery'),
),
],
selectedIndex: selectedTab,
labelType: NavigationRailLabelType.all,
leading: Padding(
padding: const EdgeInsets.only(top: 8, bottom: 16),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.asset(
'assets/icons/ProjectIcon.png',
width: 54,
height: 54,
filterQuality: FilterQuality.high,
),
),
),
onDestinationSelected: (i) => selectedTabState.value = i,
),
SecondaryViewSide(
selectedTab: selectedTab,
constraints: constraints,
),
Expanded(
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
child: MapView(
bottomSheetOuterController: _bottomSheetOuterController,
mode: mapMode,
layoutDirection: Axis.horizontal,
),
),
),
],
),
),
);
}
115 changes: 115 additions & 0 deletions example/lib/src/screens/main/layouts/vertical.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
part of '../main.dart';

class _VerticalLayout extends StatelessWidget {
const _VerticalLayout({
required DraggableScrollableController bottomSheetOuterController,
required this.mapMode,
required this.selectedTab,
required this.constrainedHeight,
}) : _bottomSheetOuterController = bottomSheetOuterController;

final DraggableScrollableController _bottomSheetOuterController;
final MapViewMode mapMode;
final int selectedTab;
final double constrainedHeight;

@override
Widget build(BuildContext context) => Scaffold(
body: BottomSheetMapWrapper(
bottomSheetOuterController: _bottomSheetOuterController,
mode: mapMode,
layoutDirection: Axis.vertical,
),
bottomSheet: SecondaryViewBottomSheet(
selectedTab: selectedTab,
controller: _bottomSheetOuterController,
),
floatingActionButton: selectedTab == 1 &&
context
.watch<RegionSelectionProvider>()
.constructedRegions
.isNotEmpty
? DelayedControllerAttachmentBuilder(
listenable: _bottomSheetOuterController,
builder: (context, _) => AnimatedBuilder(
animation: _bottomSheetOuterController,
builder: (context, _) {
final pixels = _bottomSheetOuterController.isAttached
? _bottomSheetOuterController.pixels
: 0;
return FloatingActionButton(
onPressed: () async {
await _bottomSheetOuterController.animateTo(
2 / 3,
duration: const Duration(milliseconds: 250),
curve: Curves.easeOut,
);
if (!context.mounted) return;
prepareDownloadConfigView(
context,
shouldShowConfig: pixels > 33,
);
},
tooltip:
pixels <= 33 ? 'Show regions' : 'Configure download',
child: pixels <= 33
? const Icon(Icons.library_add_check)
: const Icon(Icons.tune),
);
},
),
)
: null,
bottomNavigationBar: NavigationBar(
selectedIndex: selectedTab,
destinations: [
const NavigationDestination(
icon: Icon(Icons.map_outlined),
selectedIcon: Icon(Icons.map),
label: 'Map',
),
NavigationDestination(
icon: Selector<DownloadingProvider, bool>(
selector: (context, provider) => provider.storeName != null,
builder: (context, isDownloading, child) =>
!isDownloading ? child! : Badge(child: child),
child: const Icon(Icons.download_outlined),
),
selectedIcon: const Icon(Icons.download),
label: 'Download',
),
NavigationDestination(
icon: Selector<RecoverableRegionsProvider, int>(
selector: (context, provider) => provider.failedRegions.length,
builder: (context, count, child) => count == 0
? child!
: Badge.count(count: count, child: child),
child: const Icon(Icons.support_outlined),
),
selectedIcon: const Icon(Icons.support),
label: 'Recovery',
),
],
onDestinationSelected: (i) {
selectedTabState.value = i;
if (i == 1) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => _bottomSheetOuterController.animateTo(
32 / constrainedHeight,
duration: const Duration(milliseconds: 250),
curve: Curves.easeOut,
),
);
} else {
WidgetsBinding.instance.addPostFrameCallback(
(_) => _bottomSheetOuterController.animateTo(
0.3,
duration: const Duration(milliseconds: 250),
curve: Curves.easeOut,
),
);
}
},
),
);
}
Loading

0 comments on commit c6925be

Please sign in to comment.