feat(app): add adaptive client shell
This commit is contained in:
+32
-107
@@ -1,122 +1,47 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
import 'shell/adaptive_shell.dart';
|
||||||
runApp(const MyApp());
|
import 'shell/destination.dart';
|
||||||
}
|
|
||||||
|
export 'shell/adaptive_shell.dart';
|
||||||
|
export 'shell/destination.dart';
|
||||||
|
|
||||||
|
void main() => runApp(const MyApp());
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key, this.destinationBodies = const {}, this.cupertino});
|
||||||
|
|
||||||
|
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||||
|
final bool? cupertino;
|
||||||
|
|
||||||
// This widget is the root of your application.
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final platform = defaultTargetPlatform;
|
||||||
|
if (cupertino ??
|
||||||
|
(platform == TargetPlatform.iOS || platform == TargetPlatform.macOS)) {
|
||||||
|
return CupertinoApp(
|
||||||
|
title: 'Pipelines',
|
||||||
|
home: AdaptiveShell(
|
||||||
|
destinationBodies: destinationBodies,
|
||||||
|
cupertino: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Pipelines',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
// This is the theme of your application.
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||||
//
|
|
||||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
|
||||||
// the application has a purple toolbar. Then, without quitting the app,
|
|
||||||
// try changing the seedColor in the colorScheme below to Colors.green
|
|
||||||
// and then invoke "hot reload" (save your changes or press the "hot
|
|
||||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
|
||||||
// the command line to start the app).
|
|
||||||
//
|
|
||||||
// Notice that the counter didn't reset back to zero; the application
|
|
||||||
// state is not lost during the reload. To reset the state, use hot
|
|
||||||
// restart instead.
|
|
||||||
//
|
|
||||||
// This works for code too, not just values: Most code changes can be
|
|
||||||
// tested with just a hot reload.
|
|
||||||
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
),
|
),
|
||||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
darkTheme: ThemeData(
|
||||||
);
|
colorScheme: ColorScheme.fromSeed(
|
||||||
}
|
seedColor: Colors.blue,
|
||||||
}
|
brightness: Brightness.dark,
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
|
||||||
const MyHomePage({super.key, required this.title});
|
|
||||||
|
|
||||||
// This widget is the home page of your application. It is stateful, meaning
|
|
||||||
// that it has a State object (defined below) that contains fields that affect
|
|
||||||
// how it looks.
|
|
||||||
|
|
||||||
// This class is the configuration for the state. It holds the values (in this
|
|
||||||
// case the title) provided by the parent (in this case the App widget) and
|
|
||||||
// used by the build method of the State. Fields in a Widget subclass are
|
|
||||||
// always marked "final".
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
|
||||||
int _counter = 0;
|
|
||||||
|
|
||||||
void _incrementCounter() {
|
|
||||||
setState(() {
|
|
||||||
// This call to setState tells the Flutter framework that something has
|
|
||||||
// changed in this State, which causes it to rerun the build method below
|
|
||||||
// so that the display can reflect the updated values. If we changed
|
|
||||||
// _counter without calling setState(), then the build method would not be
|
|
||||||
// called again, and so nothing would appear to happen.
|
|
||||||
_counter++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
// This method is rerun every time setState is called, for instance as done
|
|
||||||
// by the _incrementCounter method above.
|
|
||||||
//
|
|
||||||
// The Flutter framework has been optimized to make rerunning build methods
|
|
||||||
// fast, so that you can just rebuild anything that needs updating rather
|
|
||||||
// than having to individually change instances of widgets.
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
// TRY THIS: Try changing the color here to a specific color (to
|
|
||||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
|
||||||
// change color while the other colors stay the same.
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
||||||
// Here we take the value from the MyHomePage object that was created by
|
|
||||||
// the App.build method, and use it to set our appbar title.
|
|
||||||
title: Text(widget.title),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
// Center is a layout widget. It takes a single child and positions it
|
|
||||||
// in the middle of the parent.
|
|
||||||
child: Column(
|
|
||||||
// Column is also a layout widget. It takes a list of children and
|
|
||||||
// arranges them vertically. By default, it sizes itself to fit its
|
|
||||||
// children horizontally, and tries to be as tall as its parent.
|
|
||||||
//
|
|
||||||
// Column has various properties to control how it sizes itself and
|
|
||||||
// how it positions its children. Here we use mainAxisAlignment to
|
|
||||||
// center the children vertically; the main axis here is the vertical
|
|
||||||
// axis because Columns are vertical (the cross axis would be
|
|
||||||
// horizontal).
|
|
||||||
//
|
|
||||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
|
||||||
// action in the IDE, or press "p" in the console), to see the
|
|
||||||
// wireframe for each widget.
|
|
||||||
mainAxisAlignment: .center,
|
|
||||||
children: [
|
|
||||||
const Text('You have pushed the button this many times:'),
|
|
||||||
Text(
|
|
||||||
'$_counter',
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
themeMode: ThemeMode.system,
|
||||||
onPressed: _incrementCounter,
|
home: AdaptiveShell(destinationBodies: destinationBodies),
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
),
|
||||||
|
};
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# F2 — Adaptive shell
|
||||||
|
|
||||||
|
Implemented standard adaptive navigation for Pipelines, Runs, Chat and Settings.
|
||||||
|
Material uses a bottom `NavigationBar` below 600 logical pixels and a labeled
|
||||||
|
`NavigationRail` at wider widths. Cupertino uses the native navigation bar and
|
||||||
|
tab bar. `MyApp` chooses Cupertino on iOS/macOS, leaves Material system light/dark
|
||||||
|
themes active elsewhere, and accepts injectable `WidgetBuilder` bodies through
|
||||||
|
`AdaptiveShell`; unregistered destinations are explicitly marked Not implemented.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
- `flutter test test/widget_test.dart`: passed (narrow/wide, 2x text scale,
|
||||||
|
Cupertino controls and injected destination body).
|
||||||
|
- `flutter analyze`: passed, no issues.
|
||||||
|
- Web build/browser interaction/capture: not run in this stage; no browser
|
||||||
|
automation/capture evidence available. Mobile targets are unverified.
|
||||||
|
|
||||||
|
No API capabilities are asserted or mocked. No dependencies were added.
|
||||||
+56
-20
@@ -1,30 +1,66 @@
|
|||||||
// This is a basic Flutter widget test.
|
import 'package:flutter/cupertino.dart';
|
||||||
//
|
|
||||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
||||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
|
||||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
|
||||||
// tree, read text, and verify that the values of widget properties are correct.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:pipelines_app/main.dart';
|
import 'package:pipelines_app/main.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
for (final width in [390.0, 1000.0]) {
|
||||||
// Build our app and trigger a frame.
|
testWidgets(
|
||||||
await tester.pumpWidget(const MyApp());
|
'Material shell adapts at width $width and supports large text',
|
||||||
|
(tester) async {
|
||||||
|
tester.view.physicalSize = Size(width, 900);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const MaterialApp(
|
||||||
|
home: MediaQuery(
|
||||||
|
data: MediaQueryData(textScaler: TextScaler.linear(2)),
|
||||||
|
child: AdaptiveShell(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(find.text('Pipelines'), findsWidgets);
|
||||||
|
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
||||||
|
expect(
|
||||||
|
find.byType(NavigationBar),
|
||||||
|
width < 600 ? findsOneWidget : findsNothing,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.byType(NavigationRail),
|
||||||
|
width >= 600 ? findsOneWidget : findsNothing,
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('Runs').last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Runs — Not implemented'), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
testWidgets('Cupertino shell uses native navigation controls', (
|
||||||
expect(find.text('0'), findsOneWidget);
|
tester,
|
||||||
expect(find.text('1'), findsNothing);
|
) async {
|
||||||
|
await tester.pumpWidget(const MyApp(cupertino: true));
|
||||||
|
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
||||||
|
expect(find.byType(CupertinoTabBar), findsOneWidget);
|
||||||
|
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
// Tap the '+' icon and trigger a frame.
|
testWidgets('destination content can be supplied by integration', (
|
||||||
await tester.tap(find.byIcon(Icons.add));
|
tester,
|
||||||
await tester.pump();
|
) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
// Verify that our counter has incremented.
|
MaterialApp(
|
||||||
expect(find.text('0'), findsNothing);
|
home: AdaptiveShell(
|
||||||
expect(find.text('1'), findsOneWidget);
|
destinationBodies: {
|
||||||
|
AppDestination.pipelines: (_) =>
|
||||||
|
const Text('Injected pipelines screen'),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(find.text('Injected pipelines screen'), findsOneWidget);
|
||||||
|
expect(find.text('Pipelines — Not implemented'), findsNothing);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user