fix Flutter shell platform defaults and tab state

This commit is contained in:
2026-10-21 13:28:50 +01:00
parent cee5f72b14
commit 830726fa19
6 changed files with 185 additions and 43 deletions
+30 -19
View File
@@ -30,30 +30,38 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
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'));
final contents = AppDestination.values.map((destination) {
final item = destinationDetails(destination);
return KeyedSubtree(
key: ValueKey(destination),
child:
widget.destinationBodies[destination]?.call(context) ??
Center(child: Text('${item.label} — Not implemented')),
);
}).toList();
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,
);
}),
),
],
child: SafeArea(
child: Column(
children: [
Expanded(child: _destinationStack(contents, index)),
CupertinoTabBar(
currentIndex: index,
onTap: (value) => _select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: Icon(item.cupertinoIcon),
label: item.label,
);
}),
),
],
),
),
);
}
@@ -75,7 +83,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
);
}),
),
Expanded(child: content),
Expanded(child: _destinationStack(contents, index)),
],
),
bottomNavigationBar: wide
@@ -96,4 +104,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
},
);
}
Widget _destinationStack(List<Widget> contents, int index) =>
IndexedStack(index: index, children: contents);
}
+25 -13
View File
@@ -1,17 +1,29 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.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,
),
};
({String label, IconData icon, IconData cupertinoIcon}) destinationDetails(
AppDestination value,
) => switch (value) {
AppDestination.pipelines => (
label: 'Pipelines',
icon: Icons.account_tree_outlined,
cupertinoIcon: CupertinoIcons.arrow_branch,
),
AppDestination.runs => (
label: 'Runs',
icon: Icons.play_circle_outline,
cupertinoIcon: CupertinoIcons.play_circle,
),
AppDestination.chat => (
label: 'Chat',
icon: Icons.chat_bubble_outline,
cupertinoIcon: CupertinoIcons.chat_bubble_2,
),
AppDestination.settings => (
label: 'Settings',
icon: Icons.settings_outlined,
cupertinoIcon: CupertinoIcons.gear,
),
};