From 3025e53b6e1e1def15cb1670eb77d8b2443e4c96 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 9 Apr 2024 15:27:33 +0200 Subject: [PATCH 1/5] fix: Scrollbar should be in the side of the logview --- packages/ubuntu_widgets/lib/src/log_view.dart | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/ubuntu_widgets/lib/src/log_view.dart b/packages/ubuntu_widgets/lib/src/log_view.dart index a4602255..b3f5019d 100644 --- a/packages/ubuntu_widgets/lib/src/log_view.dart +++ b/packages/ubuntu_widgets/lib/src/log_view.dart @@ -95,16 +95,26 @@ class _LogViewState extends State { @override Widget build(BuildContext context) { - return Container( - padding: widget.padding, - decoration: widget.background, - child: TextField( - controller: _controller, - decoration: widget.decoration, - maxLines: widget.maxLines, - readOnly: true, - scrollController: _scrollController, - style: widget.style, + final contentPadding = + (widget.decoration?.contentPadding ?? EdgeInsets.zero) + .add(widget.padding ?? EdgeInsets.zero); + + return DecoratedBox( + decoration: widget.background ?? const BoxDecoration(), + child: Scrollbar( + thumbVisibility: true, + controller: _scrollController, + child: SingleChildScrollView( + controller: _scrollController, + child: TextField( + controller: _controller, + decoration: (widget.decoration ?? const InputDecoration()) + .copyWith(contentPadding: contentPadding), + maxLines: widget.maxLines, + readOnly: true, + style: widget.style, + ), + ), ), ); } From b3e72fcea308bbee994140f5c64d3da4eab39f54 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 9 Apr 2024 16:36:31 +0200 Subject: [PATCH 2/5] test: Run all tests --- melos.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/melos.yaml b/melos.yaml index 37a8d6e1..f877be67 100644 --- a/melos.yaml +++ b/melos.yaml @@ -60,7 +60,7 @@ scripts: # run integration tests in all packages integration_test: > - melos exec -c 1 --fail-fast --dir-exists=integration_test -- \ + melos exec -c 1 --dir-exists=integration_test -- \ flutter test integration_test # runs "flutter pub " in all packages @@ -68,7 +68,7 @@ scripts: # run tests in all packages test: > - melos exec -c 1 --fail-fast --dir-exists=test -- \ + melos exec -c 1 --dir-exists=test -- \ flutter test # run pub upgrade in all packages From 7e262daa574d540ecd47386986f68435d89adcf0 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 9 Apr 2024 16:36:46 +0200 Subject: [PATCH 3/5] chore: Pin getIt to 7.4.1 --- packages/ubuntu_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ubuntu_service/pubspec.yaml b/packages/ubuntu_service/pubspec.yaml index 2ff2021c..badb18ae 100644 --- a/packages/ubuntu_service/pubspec.yaml +++ b/packages/ubuntu_service/pubspec.yaml @@ -9,7 +9,7 @@ environment: sdk: '>=3.0.0 <4.0.0' dependencies: - get_it: ^7.4.1 + get_it: 7.4.1 meta: ^1.11.0 dev_dependencies: From 0e9850ce15dca1c87d5c64249f3169c081dcbf7f Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 9 Apr 2024 16:37:08 +0200 Subject: [PATCH 4/5] fix!: Remove support for max lines --- packages/ubuntu_widgets/lib/src/log_view.dart | 17 +++++---- .../ubuntu_widgets/test/log_view_test.dart | 37 +++++++++++++------ 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/packages/ubuntu_widgets/lib/src/log_view.dart b/packages/ubuntu_widgets/lib/src/log_view.dart index b3f5019d..65da6ad9 100644 --- a/packages/ubuntu_widgets/lib/src/log_view.dart +++ b/packages/ubuntu_widgets/lib/src/log_view.dart @@ -7,20 +7,17 @@ class LogView extends StatefulWidget { /// Creates a log view. A stream of [log] lines is required. const LogView({ required this.log, - this.maxLines, this.padding, this.decoration, this.background, this.style, + this.scrollController, super.key, }); /// The stream of log lines to show. final Stream log; - /// See [TextField.maxLines] - final int? maxLines; - /// Padding around the log text. final EdgeInsetsGeometry? padding; @@ -33,6 +30,9 @@ class LogView extends StatefulWidget { /// See [TextField.style] final TextStyle? style; + /// See [TextField.scrollController] + final ScrollController? scrollController; + @override State createState() => _LogViewState(); } @@ -40,7 +40,7 @@ class LogView extends StatefulWidget { class _LogViewState extends State { StreamSubscription? _subscription; final _controller = TextEditingController(); - final _scrollController = ScrollController(); + late final _scrollController = widget.scrollController ?? ScrollController(); @override void initState() { @@ -98,19 +98,20 @@ class _LogViewState extends State { final contentPadding = (widget.decoration?.contentPadding ?? EdgeInsets.zero) .add(widget.padding ?? EdgeInsets.zero); + final decoration = (widget.decoration ?? const InputDecoration()) + .copyWith(contentPadding: contentPadding); return DecoratedBox( decoration: widget.background ?? const BoxDecoration(), child: Scrollbar( + key: const ValueKey('LogViewScrollbar'), thumbVisibility: true, controller: _scrollController, child: SingleChildScrollView( controller: _scrollController, child: TextField( controller: _controller, - decoration: (widget.decoration ?? const InputDecoration()) - .copyWith(contentPadding: contentPadding), - maxLines: widget.maxLines, + decoration: decoration, readOnly: true, style: widget.style, ), diff --git a/packages/ubuntu_widgets/test/log_view_test.dart b/packages/ubuntu_widgets/test/log_view_test.dart index d7820e8d..98a5336d 100644 --- a/packages/ubuntu_widgets/test/log_view_test.dart +++ b/packages/ubuntu_widgets/test/log_view_test.dart @@ -9,11 +9,18 @@ import 'package:ubuntu_widgets/ubuntu_widgets.dart'; void main() { testWidgets('append lines', (tester) async { final log = StreamController(sync: true); + final scrollController = ScrollController(); await tester.pumpWidget( MaterialApp( home: Scaffold( - body: LogView(log: log.stream, maxLines: 2), + body: SizedBox( + height: 5, + child: LogView( + log: log.stream, + scrollController: scrollController, + ), + ), ), ), ); @@ -23,26 +30,23 @@ void main() { final controller = textField.controller; expect(controller, isNotNull); - final scrollController = textField.scrollController; - expect(scrollController, isNotNull); - log.add('line 1'); await tester.pump(); expect(controller!.text, equals('line 1')); - expect(scrollController!.position.extentAfter, equals(0.0)); - expect(scrollController.position.maxScrollExtent, equals(0.0)); + expect(scrollController.position.extentAfter, equals(0.0)); + expect(scrollController.position.maxScrollExtent, isPositive); log.add('line 2'); await tester.pump(); expect(controller.text, equals('line 1\nline 2')); expect(scrollController.position.extentAfter, equals(0.0)); - expect(scrollController.position.maxScrollExtent, equals(0.0)); + expect(scrollController.position.maxScrollExtent, isPositive); log.add('line 3'); - await tester.pump(); + await tester.pumpAndSettle(); expect(controller.text, equals('line 1\nline 2\nline 3')); expect(scrollController.position.extentAfter, equals(0.0)); - expect(scrollController.position.maxScrollExtent, greaterThan(0.0)); + expect(scrollController.position.maxScrollExtent, isPositive); }); testWidgets('rebuild with different stream', (tester) async { @@ -78,7 +82,14 @@ void main() { } await tester.pumpWidget( - MaterialApp(home: Scaffold(body: LogView(log: log.stream, maxLines: 2))), + MaterialApp( + home: Scaffold( + body: SizedBox( + height: 20, + child: LogView(log: log.stream), + ), + ), + ), ); FlutterErrorDetails? error; @@ -99,7 +110,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: LogView(log: log.stream, maxLines: 2), + body: SizedBox(height: 20, child: LogView(log: log.stream)), ), ), ); @@ -109,7 +120,9 @@ void main() { final controller = textField.controller; expect(controller, isNotNull); - final scrollController = textField.scrollController; + final scrollView = tester + .widget(find.byType(SingleChildScrollView)); + final scrollController = scrollView.controller; expect(scrollController, isNotNull); for (var i = 1; i < 6; i++) { From c36d7be9afb25290ea85f539abac184eb4d48c42 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 9 Apr 2024 17:02:21 +0200 Subject: [PATCH 5/5] Set dependency range for get_it --- packages/ubuntu_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ubuntu_service/pubspec.yaml b/packages/ubuntu_service/pubspec.yaml index badb18ae..9959230a 100644 --- a/packages/ubuntu_service/pubspec.yaml +++ b/packages/ubuntu_service/pubspec.yaml @@ -9,7 +9,7 @@ environment: sdk: '>=3.0.0 <4.0.0' dependencies: - get_it: 7.4.1 + get_it: '>=7.4.1 <7.6.8' meta: ^1.11.0 dev_dependencies: