diff --git a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart index d3bd0940..c9fd7aa2 100644 --- a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart +++ b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart @@ -4,12 +4,11 @@ import 'package:alice/model/alice_http_call.dart'; import 'package:alice/ui/call_details/model/alice_menu_item.dart'; import 'package:alice/ui/calls_list/model/alice_calls_list_sort_option.dart'; import 'package:alice/ui/calls_list/model/alice_calls_list_tab_item.dart'; +import 'package:alice/ui/calls_list/widget/alice_inspector_screen.dart'; import 'package:alice/ui/calls_list/widget/alice_sort_dialog.dart'; import 'package:alice/ui/common/alice_dialog.dart'; import 'package:alice/ui/common/alice_navigation.dart'; import 'package:alice/ui/common/alice_page.dart'; -import 'package:alice/ui/calls_list/widget/alice_calls_list_screen.dart'; -import 'package:alice/ui/calls_list/widget/alice_empty_logs_widget.dart'; import 'package:alice/ui/calls_list/widget/alice_logs_screen.dart'; import 'package:alice/utils/alice_theme.dart'; import 'package:flutter/material.dart'; @@ -32,7 +31,7 @@ class AliceCallsListPage extends StatefulWidget { } class _AliceCallsListPageState extends State - with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { + with SingleTickerProviderStateMixin { final TextEditingController _queryTextEditingController = TextEditingController(); final List _tabItems = AliceCallsListTabItem.values; @@ -76,13 +75,8 @@ class _AliceCallsListPageState extends State /// Returns [true] when logger tab is opened. bool get isLoggerTab => _selectedIndex == 1; - @override - bool get wantKeepAlive => true; - @override Widget build(BuildContext context) { - super.build(context); - return AlicePage( core: aliceCore, child: Scaffold( @@ -128,27 +122,12 @@ class _AliceCallsListPageState extends State body: TabBarView( controller: _tabController, children: [ - StreamBuilder>( - stream: aliceCore.callsStream, - builder: (context, AsyncSnapshot> snapshot) { - final List calls = snapshot.data ?? []; - final String query = _queryTextEditingController.text.trim(); - if (query.isNotEmpty) { - calls.removeWhere((AliceHttpCall call) => !call.endpoint - .toLowerCase() - .contains(query.toLowerCase())); - } - if (calls.isNotEmpty) { - return AliceCallsListScreen( - calls: calls, - sortOption: _sortOption, - sortAscending: _sortAscending, - onListItemClicked: _onListItemPressed, - ); - } else { - return const AliceEmptyLogsWidget(); - } - }, + AliceInspectorScreen( + aliceCore: aliceCore, + queryTextEditingController: _queryTextEditingController, + sortOption: _sortOption, + sortAscending: _sortAscending, + onListItemPressed: _onListItemPressed, ), AliceLogsScreen( scrollController: _scrollController, diff --git a/packages/alice/lib/ui/calls_list/widget/alice_inspector_screen.dart b/packages/alice/lib/ui/calls_list/widget/alice_inspector_screen.dart new file mode 100644 index 00000000..a90b8c6a --- /dev/null +++ b/packages/alice/lib/ui/calls_list/widget/alice_inspector_screen.dart @@ -0,0 +1,59 @@ +import 'package:alice/core/alice_core.dart'; +import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/ui/calls_list/model/alice_calls_list_sort_option.dart'; +import 'package:alice/ui/calls_list/widget/alice_calls_list_screen.dart'; +import 'package:alice/ui/calls_list/widget/alice_empty_logs_widget.dart'; +import 'package:flutter/material.dart'; + +class AliceInspectorScreen extends StatefulWidget { + const AliceInspectorScreen({ + super.key, + required this.aliceCore, + required this.queryTextEditingController, + required this.sortOption, + required this.sortAscending, + required this.onListItemPressed, + }); + + final AliceCore aliceCore; + final TextEditingController queryTextEditingController; + final AliceCallsListSortOption sortOption; + final bool sortAscending; + final void Function(AliceHttpCall) onListItemPressed; + + @override + State createState() => _AliceInspectorScreenState(); +} + +class _AliceInspectorScreenState extends State + with AutomaticKeepAliveClientMixin { + @override + bool get wantKeepAlive => true; + + @override + Widget build(BuildContext context) { + super.build(context); + + return StreamBuilder>( + stream: widget.aliceCore.callsStream, + builder: (context, AsyncSnapshot> snapshot) { + final List calls = snapshot.data ?? []; + final String query = widget.queryTextEditingController.text.trim(); + if (query.isNotEmpty) { + calls.removeWhere((AliceHttpCall call) => + !call.endpoint.toLowerCase().contains(query.toLowerCase())); + } + if (calls.isNotEmpty) { + return AliceCallsListScreen( + calls: calls, + sortOption: widget.sortOption, + sortAscending: widget.sortAscending, + onListItemClicked: widget.onListItemPressed, + ); + } else { + return const AliceEmptyLogsWidget(); + } + }, + ); + } +}