From cee5f72b144a4e217453e01e60d1e15d20cdf158 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 21 Oct 2026 13:22:58 +0100 Subject: [PATCH] feat(app): add adaptive client shell --- app/lib/main.dart | 139 +++++++----------------------- app/lib/shell/adaptive_shell.dart | 99 +++++++++++++++++++++ app/lib/shell/destination.dart | 17 ++++ app/notes/F2.md | 18 ++++ app/test/widget_test.dart | 76 +++++++++++----- 5 files changed, 222 insertions(+), 127 deletions(-) create mode 100644 app/lib/shell/adaptive_shell.dart create mode 100644 app/lib/shell/destination.dart create mode 100644 app/notes/F2.md diff --git a/app/lib/main.dart b/app/lib/main.dart index 244a702c..0c08d900 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -1,122 +1,47 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -void main() { - runApp(const MyApp()); -} +import 'shell/adaptive_shell.dart'; +import 'shell/destination.dart'; + +export 'shell/adaptive_shell.dart'; +export 'shell/destination.dart'; + +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { - const MyApp({super.key}); + const MyApp({super.key, this.destinationBodies = const {}, this.cupertino}); + + final Map destinationBodies; + final bool? cupertino; - // This widget is the root of your application. @override 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( - title: 'Flutter Demo', + title: 'Pipelines', theme: ThemeData( - // This is the theme of your application. - // - // 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), + colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -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 createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - 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, - ), - ], + darkTheme: ThemeData( + colorScheme: ColorScheme.fromSeed( + seedColor: Colors.blue, + brightness: Brightness.dark, ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), + themeMode: ThemeMode.system, + home: AdaptiveShell(destinationBodies: destinationBodies), ); } } diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart new file mode 100644 index 00000000..6964f4b0 --- /dev/null +++ b/app/lib/shell/adaptive_shell.dart @@ -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 destinationBodies; + final bool cupertino; + + @override + State createState() => _AdaptiveShellState(); +} + +class _AdaptiveShellState extends State { + AppDestination _selected = AppDestination.pipelines; + + void _select(AppDestination destination) => + setState(() => _selected = destination); + + List _items(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, + ); + }), + ), + ); + }, + ); + } +} diff --git a/app/lib/shell/destination.dart b/app/lib/shell/destination.dart new file mode 100644 index 00000000..e8d0c373 --- /dev/null +++ b/app/lib/shell/destination.dart @@ -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, + ), + }; diff --git a/app/notes/F2.md b/app/notes/F2.md new file mode 100644 index 00000000..e70e653a --- /dev/null +++ b/app/notes/F2.md @@ -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. diff --git a/app/test/widget_test.dart b/app/test/widget_test.dart index 41dc58b8..e10bf144 100644 --- a/app/test/widget_test.dart +++ b/app/test/widget_test.dart @@ -1,30 +1,66 @@ -// This is a basic Flutter widget test. -// -// 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/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/main.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + for (final width in [390.0, 1000.0]) { + testWidgets( + '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. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); + testWidgets('Cupertino shell uses native navigation controls', ( + tester, + ) 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. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); + testWidgets('destination content can be supplied by integration', ( + tester, + ) async { + await tester.pumpWidget( + MaterialApp( + home: AdaptiveShell( + destinationBodies: { + AppDestination.pipelines: (_) => + const Text('Injected pipelines screen'), + }, + ), + ), + ); + expect(find.text('Injected pipelines screen'), findsOneWidget); + expect(find.text('Pipelines — Not implemented'), findsNothing); }); }