Skip to content

Commit

Permalink
feat: examples/alice_objectbox
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Jun 28, 2024
1 parent f3e9d71 commit 1cb99eb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 29 deletions.
37 changes: 8 additions & 29 deletions packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,7 +31,7 @@ class AliceCallsListPage extends StatefulWidget {
}

class _AliceCallsListPageState extends State<AliceCallsListPage>
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
with SingleTickerProviderStateMixin {
final TextEditingController _queryTextEditingController =
TextEditingController();
final List<AliceCallsListTabItem> _tabItems = AliceCallsListTabItem.values;
Expand Down Expand Up @@ -76,13 +75,8 @@ class _AliceCallsListPageState extends State<AliceCallsListPage>
/// 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(
Expand Down Expand Up @@ -128,27 +122,12 @@ class _AliceCallsListPageState extends State<AliceCallsListPage>
body: TabBarView(
controller: _tabController,
children: [
StreamBuilder<List<AliceHttpCall>>(
stream: aliceCore.callsStream,
builder: (context, AsyncSnapshot<List<AliceHttpCall>> snapshot) {
final List<AliceHttpCall> 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AliceInspectorScreen> createState() => _AliceInspectorScreenState();
}

class _AliceInspectorScreenState extends State<AliceInspectorScreen>
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;

@override
Widget build(BuildContext context) {
super.build(context);

return StreamBuilder<List<AliceHttpCall>>(
stream: widget.aliceCore.callsStream,
builder: (context, AsyncSnapshot<List<AliceHttpCall>> snapshot) {
final List<AliceHttpCall> 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();
}
},
);
}
}

0 comments on commit 1cb99eb

Please sign in to comment.