feat(app): add adaptive client shell
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'destination.dart';
|
||||
|
||||
class AdaptiveShell extends StatefulWidget {
|
||||
const AdaptiveShell({
|
||||
super.key,
|
||||
this.destinationBodies = const {},
|
||||
this.cupertino = false,
|
||||
});
|
||||
|
||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
||||
}
|
||||
|
||||
class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
AppDestination _selected = AppDestination.pipelines;
|
||||
|
||||
void _select(AppDestination destination) =>
|
||||
setState(() => _selected = destination);
|
||||
|
||||
List<T> _items<T>(T Function(AppDestination) build) =>
|
||||
AppDestination.values.map(build).toList();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final index = AppDestination.values.indexOf(_selected);
|
||||
final details = destinationDetails(_selected);
|
||||
final content =
|
||||
widget.destinationBodies[_selected]?.call(context) ??
|
||||
Center(child: Text('${details.label} — Not implemented'));
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= 600;
|
||||
if (widget.cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(middle: Text(details.label)),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(child: content),
|
||||
CupertinoTabBar(
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(AppDestination.values[value]),
|
||||
items: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return BottomNavigationBarItem(
|
||||
icon: Icon(item.icon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(details.label)),
|
||||
body: Row(
|
||||
children: [
|
||||
if (wide)
|
||||
NavigationRail(
|
||||
selectedIndex: index,
|
||||
onDestinationSelected: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
labelType: NavigationRailLabelType.all,
|
||||
destinations: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return NavigationRailDestination(
|
||||
icon: Icon(item.icon),
|
||||
label: Text(item.label),
|
||||
);
|
||||
}),
|
||||
),
|
||||
Expanded(child: content),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: wide
|
||||
? null
|
||||
: NavigationBar(
|
||||
selectedIndex: index,
|
||||
onDestinationSelected: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
destinations: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return NavigationDestination(
|
||||
icon: Icon(item.icon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum AppDestination { pipelines, runs, chat, settings }
|
||||
|
||||
({String label, IconData icon}) destinationDetails(AppDestination value) =>
|
||||
switch (value) {
|
||||
AppDestination.pipelines => (
|
||||
label: 'Pipelines',
|
||||
icon: Icons.account_tree_outlined,
|
||||
),
|
||||
AppDestination.runs => (label: 'Runs', icon: Icons.play_circle_outline),
|
||||
AppDestination.chat => (label: 'Chat', icon: Icons.chat_bubble_outline),
|
||||
AppDestination.settings => (
|
||||
label: 'Settings',
|
||||
icon: Icons.settings_outlined,
|
||||
),
|
||||
};
|
||||
Reference in New Issue
Block a user