diff --git a/oui/lib/src/app/oui_app.dart b/oui/lib/src/app/oui_app.dart index f518f57..2312f45 100644 --- a/oui/lib/src/app/oui_app.dart +++ b/oui/lib/src/app/oui_app.dart @@ -47,7 +47,7 @@ class OuiApp extends StatelessWidget { this.config = const OuiConfig(), }) : _registry = OuiScreenRegistry(root, null) { _routerInformationParser = OuiRouteInformationParser(_registry); - _router = OuiRouter(_registry); + _router = OuiRouter(); } @override diff --git a/oui/lib/src/router/oui_path.dart b/oui/lib/src/router/oui_path.dart index 373db3c..79558b1 100644 --- a/oui/lib/src/router/oui_path.dart +++ b/oui/lib/src/router/oui_path.dart @@ -188,8 +188,6 @@ class OuiPath { /// Returns a new [OuiPath] with the given [segments] appended to the end. /// If [segments] is empty, returns this path. OuiPath add(List segments) { - assert( - segments.every((s) => s != null), 'Cannot add null segments to path'); if (segments.isEmpty) { return this; } diff --git a/oui/lib/src/router/oui_router.dart b/oui/lib/src/router/oui_router.dart index 66dd613..e73bf83 100644 --- a/oui/lib/src/router/oui_router.dart +++ b/oui/lib/src/router/oui_router.dart @@ -2,15 +2,12 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'oui_path_match.dart'; import '../scaffold/oui_scaffold.dart'; -import '../screens/oui_screen_registry.dart'; class OuiRouter extends RouterDelegate with ChangeNotifier { - final OuiScreenRegistry _registry; - OuiPathMatch _activeMatch = OuiPathMatch.noMatch; OuiPathMatch get match => _activeMatch; - OuiRouter(this._registry); + OuiRouter(); @override OuiPathMatch? get currentConfiguration => _activeMatch; diff --git a/oui/lib/src/utils/background.dart b/oui/lib/src/utils/background.dart index cc284af..7a742ba 100644 --- a/oui/lib/src/utils/background.dart +++ b/oui/lib/src/utils/background.dart @@ -5,24 +5,23 @@ class Background extends StatelessWidget { final Gradient? gradient; final Widget Function(BuildContext)? custom; - const Background({ - super.key, + const Background._({ this.color, this.gradient, this.custom, }); - factory Background.color(Color color) => Background(color: color); + factory Background.color(Color color) => Background._(color: color); factory Background.gradient(Gradient gradient) => - Background(gradient: gradient); + Background._(gradient: gradient); factory Background.custom( Widget Function(BuildContext) custom, { Color? color, Gradient? gradient, }) => - Background( + Background._( color: color, gradient: gradient, custom: custom, @@ -37,20 +36,25 @@ class Background extends StatelessWidget { decoration: BoxDecoration(gradient: gradient), ); } else if (color != null) { - background = Container(color: color); + background = Container( + decoration: BoxDecoration(color: color), + ); } - if (custom != null && background != null) { - background = Stack( - children: [ - background, - custom!(context), - ], - ); - } else { - background = custom!(context); + if (custom != null) { + if (background != null) { + background = Stack( + children: [ + background, + custom!(context), + ], + ); + } else { + background = custom!(context); + } } - return background; + // Fallback to an empty widget if all parameters are null + return background ?? const SizedBox.shrink(); } } diff --git a/oui/test/background_test.dart b/oui/test/background_test.dart new file mode 100644 index 0000000..8e816ff --- /dev/null +++ b/oui/test/background_test.dart @@ -0,0 +1,97 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:oui/src/utils/background.dart'; + +void main() { + testWidgets('Background with color', (WidgetTester tester) async { + await tester.pumpWidget( + WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (context, _) => Background.color(const Color(0xFFFF0000)), + ), + ); + + final container = tester.widget(find.byType(Container)); + expect( + (container.decoration as BoxDecoration?)?.color, + const Color(0xFFFF0000), + ); + expect(find.byType(Container), findsOneWidget); + }); + + testWidgets('Background with gradient', (WidgetTester tester) async { + const gradient = LinearGradient( + colors: [Color(0xFFFF0000), Color(0xFF0000FF)], + begin: Alignment.centerLeft, + end: Alignment.centerRight, + ); + + await tester.pumpWidget( + WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (context, _) => Background.gradient(gradient), + ), + ); + + final container = tester.widget(find.byType(Container)); + final boxDecoration = container.decoration as BoxDecoration?; + expect(boxDecoration?.gradient, gradient); + }); + + testWidgets('Background with custom widget', (WidgetTester tester) async { + await tester.pumpWidget( + WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (context, _) => Background.custom( + (context) => const Text('Custom Widget'), + ), + ), + ); + + expect(find.text('Custom Widget'), findsOneWidget); + }); + + testWidgets('Background with color and custom widget', + (WidgetTester tester) async { + await tester.pumpWidget( + WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (context, _) => Background.custom( + (context) => const Text('Custom Widget'), + color: const Color(0xFFFF0000), + ), + ), + ); + + final container = tester.widget(find.byType(Container)); + expect( + (container.decoration as BoxDecoration?)?.color, + const Color(0xFFFF0000), + ); + expect(find.text('Custom Widget'), findsOneWidget); + }); + + testWidgets('Background with gradient and custom widget', + (WidgetTester tester) async { + const gradient = LinearGradient( + colors: [Color(0xFFFF0000), Color(0xFF0000FF)], + begin: Alignment.centerLeft, + end: Alignment.centerRight, + ); + + await tester.pumpWidget( + WidgetsApp( + color: const Color(0xFFFFFFFF), + builder: (context, _) => Background.custom( + (context) => const Text('Custom Widget'), + gradient: gradient, + ), + ), + ); + + final container = tester.widget(find.byType(Container)); + final boxDecoration = container.decoration as BoxDecoration?; + expect(boxDecoration?.gradient, gradient); + expect(find.text('Custom Widget'), findsOneWidget); + }); +}