Skip to content

Commit

Permalink
fix: fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhomlala committed Jul 7, 2024
1 parent 4e6a595 commit ed56220
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 81 deletions.
12 changes: 3 additions & 9 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Alice alice = Alice();
2. Add navigator key to your application:

```dart
MaterialApp
(
navigatorKey: alice.getNavigatorKey(), home: ...)
MaterialApp(navigatorKey: alice.getNavigatorKey(), home: ...);
```

You need to add this navigator key in order to show inspector UI.
Expand All @@ -26,10 +24,7 @@ Alice alice = Alice(configuration: AliceConfiguration(navigatorKey: yourNavigato
If you need to pass navigatorKey lazily, you can use:

```dart
alice.setNavigatorKey
(
yourNavigatorKeyHere
);
alice.setNavigatorKey(yourNavigatorKeyHere);
```

This is minimal configuration required to run Alice. Can set optional settings in Alice constructor,
Expand Down Expand Up @@ -61,8 +56,7 @@ value is @mipmap/ic_launcher.

```dart
Alice alice = Alice(
configuration: AliceConfiguration(notificationIcon: "myNotificationIconResourceName"));
Alice alice = Alice(configuration: AliceConfiguration(notificationIcon: "myNotificationIconResourceName"));
```

If you want to change the Directionality of Alice, you can use the `directionality` parameter. If
Expand Down
1 change: 1 addition & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
```yaml
dependencies:
objectbox: any
alice_objectbox: ^1.0.1
```
Expand Down
3 changes: 2 additions & 1 deletion examples/alice_chopper/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
final AliceChopperAdapter _aliceChopperAdapter = AliceChopperAdapter();

late final Alice _alice = Alice(configuration: AliceConfiguration())
final configuration = AliceConfiguration();
late final Alice _alice = Alice(configuration: configuration)
..addAdapter(_aliceChopperAdapter);

late final ChopperClient _chopper = ChopperClient(
Expand Down
3 changes: 2 additions & 1 deletion examples/alice_dio/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
late final AliceDioAdapter _aliceDioAdapter = AliceDioAdapter();

late final Alice _alice = Alice(configuration: AliceConfiguration())
final configuration = AliceConfiguration();
late final Alice _alice = Alice(configuration: configuration)
..addAdapter(_aliceDioAdapter);

late final Dio _dio = Dio(BaseOptions(followRedirects: false))
Expand Down
3 changes: 2 additions & 1 deletion examples/alice_http/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
late final AliceHttpAdapter _aliceHttpAdapter = AliceHttpAdapter();

late final Alice _alice = Alice(configuration: AliceConfiguration())
final configuration = AliceConfiguration();
late final Alice _alice = Alice(configuration: configuration)
..addAdapter(_aliceHttpAdapter);

@override
Expand Down
3 changes: 2 additions & 1 deletion examples/alice_http_client/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class _MyAppState extends State<MyApp> {
late final AliceHttpClientAdapter _httpClientAdapter =
AliceHttpClientAdapter();

late final Alice _alice = Alice(configuration: AliceConfiguration())
final configuration = AliceConfiguration();
late final Alice _alice = Alice(configuration: configuration)
..addAdapter(_httpClientAdapter);

@override
Expand Down
13 changes: 7 additions & 6 deletions examples/alice_objectbox/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
late final AliceHttpAdapter _aliceHttpAdapter = AliceHttpAdapter();

late final Alice _alice = Alice(
configuration: AliceConfiguration(
storage: AliceObjectBox(
store: widget.store,
maxCallsCount: 1000,
),
late final configuration = AliceConfiguration(
storage: AliceObjectBox(
store: widget.store,
maxCallsCount: 1000,
),
);
late final Alice _alice = Alice(
configuration: configuration
)..addAdapter(_aliceHttpAdapter);

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/alice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 1.0.0-dev.10

* [BREAKING_CHANGE] Removed maxCallsCount. To change call count, use `storage` constructor parameter
* [BREAKING_CHANGE] Removed `maxCallsCount`. To change call count, use `storage` constructor parameter
with call count.
* [BREAKING_CHANGE] Replaced configuration parameter of Alice with `AliceConfiguration`.
* Fixed issue with invalid count of calls in notification.
Expand Down
15 changes: 7 additions & 8 deletions packages/alice/lib/core/alice_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AliceCore {

/// Set custom navigation key. This will help if there's route library.
void setNavigatorKey(GlobalKey<NavigatorState> navigatorKey) {
_configuration = _configuration.copyWith(newNavigatorKey: navigatorKey);
_configuration = _configuration.copyWith(navigatorKey: navigatorKey);
}

/// Dispose subjects and subscriptions
Expand All @@ -79,7 +79,7 @@ class AliceCore {

/// Opens Http calls inspector. This will navigate user to the new fullscreen
/// page where all listened http calls can be viewed.
void navigateToCallListScreen() {
Future<void> navigateToCallListScreen() async {
final BuildContext? context = getContext();
if (context == null) {
AliceUtils.log(
Expand All @@ -90,8 +90,8 @@ class AliceCore {
}
if (!_isInspectorOpened) {
_isInspectorOpened = true;
AliceNavigation.navigateToCallsList(core: this)
.then((_) => _isInspectorOpened = false);
await AliceNavigation.navigateToCallsList(core: this);
_isInspectorOpened = false;
}
}

Expand Down Expand Up @@ -127,10 +127,9 @@ class AliceCore {
List<AliceHttpCall> getCalls() => _configuration.aliceStorage.getCalls();

/// Save all calls to file.
Future<AliceExportResult> saveCallsToFile(BuildContext context) {
return AliceExportHelper.saveCallsToFile(
context, _configuration.aliceStorage.getCalls());
}
Future<AliceExportResult> saveCallsToFile(BuildContext context) =>
AliceExportHelper.saveCallsToFile(
context, _configuration.aliceStorage.getCalls());

/// Adds new log to Alice logger.
void addLog(AliceLog log) => _configuration.aliceLogger.add(log);
Expand Down
9 changes: 5 additions & 4 deletions packages/alice/lib/core/alice_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dart:io' show Process, ProcessResult;

import 'package:alice/helper/operating_system.dart';
import 'package:alice/model/alice_log.dart';
import 'package:alice/utils/num_comparison.dart';
import 'package:rxdart/rxdart.dart';

/// Logger used to handle logs from application.
class AliceLogger {
/// Maximum logs size. If null, logs will be not rotated.
final int? maximumSize;
/// Maximum logs size. If 0, logs will be not rotated.
final int maximumSize;

/// Subject which keeps logs.
final BehaviorSubject<List<AliceLog>> _logsSubject;
Expand All @@ -22,7 +23,7 @@ class AliceLogger {
List<AliceLog> get logs => _logsSubject.value;

/// Adds all logs.
void addAll(List<AliceLog> logs) {
void addAll(Iterable<AliceLog> logs) {
for (var log in logs) {
add(log);
}
Expand All @@ -33,7 +34,7 @@ class AliceLogger {
void add(AliceLog log) {
final values = _logsSubject.value;
final count = values.length;
if (maximumSize != null && count >= maximumSize!) {
if (maximumSize > 0 && count.gte(maximumSize)) {
values.removeAt(0);
}

Expand Down
11 changes: 4 additions & 7 deletions packages/alice/lib/core/alice_memory_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ class AliceMemoryStorage implements AliceStorage {
(call.response?.status.lt(400) ?? false))
.length,
errors: calls
.where(
(AliceHttpCall call) =>
((call.response?.status.gte(400) ?? false) &&
(call.response?.status.lt(600) ?? false)) ||
call.response?.status == -1 ||
call.response?.status == 0,
)
.where((AliceHttpCall call) =>
((call.response?.status.gte(400) ?? false) &&
(call.response?.status.lt(600) ?? false)) ||
const [-1, 0].contains(call.response?.status))
.length,
loading: calls.where((AliceHttpCall call) => call.loading).length,
);
Expand Down
2 changes: 2 additions & 0 deletions packages/alice/lib/core/alice_translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class AliceTranslations {
AliceTranslationKey.callsListStats: "Stats",
AliceTranslationKey.callsListSave: "Save",
AliceTranslationKey.logsEmpty: "There are no logs to show",
AliceTranslationKey.logsError: "Failed to display error",
AliceTranslationKey.logsItemError: "Error:",
AliceTranslationKey.logsItemStackTrace: "Stack trace:",
AliceTranslationKey.logsCopied: "Copied to clipboard.",
Expand Down Expand Up @@ -254,6 +255,7 @@ class AliceTranslations {
AliceTranslationKey.callsListStats: "Statystyki",
AliceTranslationKey.callsListSave: "Zapis",
AliceTranslationKey.logsEmpty: "Brak rezultatów",
AliceTranslationKey.logsError: "Problem z wyświetleniem logów.",
AliceTranslationKey.logsItemError: "Błąd:",
AliceTranslationKey.logsItemStackTrace: "Ślad stosu:",
AliceTranslationKey.logsCopied: "Skopiowano do schowka.",
Expand Down
30 changes: 19 additions & 11 deletions packages/alice/lib/model/alice_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,23 @@ class AliceConfiguration {
aliceLogger = logger ?? AliceLogger(maximumSize: _defaultMaxLogs);

AliceConfiguration copyWith({
required GlobalKey<NavigatorState> newNavigatorKey,
}) {
return AliceConfiguration(
showNotification: showNotification,
showInspectorOnShake: showInspectorOnShake,
notificationIcon: notificationIcon,
directionality: directionality,
showShareButton: showShareButton,
navigatorKey: newNavigatorKey,
);
}
GlobalKey<NavigatorState>? navigatorKey,
bool? showNotification,
bool? showInspectorOnShake,
String? notificationIcon,
TextDirection? directionality,
bool? showShareButton,
AliceStorage? aliceStorage,
AliceLogger? aliceLogger,
}) =>
AliceConfiguration(
showNotification: showNotification ?? this.showNotification,
showInspectorOnShake: showInspectorOnShake ?? this.showInspectorOnShake,
notificationIcon: notificationIcon ?? this.notificationIcon,
directionality: directionality ?? this.directionality,
showShareButton: showShareButton ?? this.showShareButton,
navigatorKey: navigatorKey ?? this.navigatorKey,
storage: aliceStorage ?? this.aliceStorage,
logger: aliceLogger ?? this.aliceLogger,
);
}
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum AliceTranslationKey {
callsListStats,
callsListSave,
logsEmpty,
logsError,
logsItemError,
logsItemStackTrace,
logsCopied,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:alice/model/alice_translation.dart';
import 'package:alice/ui/common/alice_context_ext.dart';
import 'package:alice/ui/common/alice_theme.dart';
import 'package:flutter/material.dart';

/// Widget which renders empty text for calls list.
class AliceErrorLogsWidget extends StatelessWidget {
const AliceErrorLogsWidget({
super.key,
});

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 32),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.error_outline,
color: AliceTheme.red,
),
const SizedBox(height: 6),
Text(
context.i18n(AliceTranslationKey.logsItemError),
style: const TextStyle(fontSize: 18),
),
],
),
),
);
}
}
17 changes: 14 additions & 3 deletions packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:convert';

import 'package:alice/model/alice_log.dart';
import 'package:alice/model/alice_translation.dart';
import 'package:alice/ui/calls_list/widget/alice_empty_logs_widget.dart';
import 'package:alice/ui/calls_list/widget/alice_error_logs_widget.dart';
import 'package:alice/ui/common/alice_context_ext.dart';
import 'package:alice/ui/common/alice_scroll_behavior.dart';
import 'package:alice/ui/common/alice_theme.dart';
Expand All @@ -14,13 +16,11 @@ class AliceLogListWidget extends StatefulWidget {
const AliceLogListWidget({
required this.logsStream,
required this.scrollController,
required this.emptyWidget,
super.key,
});

final Stream<List<AliceLog>>? logsStream;
final ScrollController? scrollController;
final Widget emptyWidget;

@override
State<AliceLogListWidget> createState() => _AliceLogListWidgetState();
Expand All @@ -35,9 +35,20 @@ class _AliceLogListWidgetState extends State<AliceLogListWidget> {
return StreamBuilder<List<AliceLog>>(
stream: widget.logsStream,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.none ||
snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
}

if (snapshot.hasError) {
return const AliceErrorLogsWidget();
}

final logs = snapshot.data ?? [];
if (logs.isEmpty) {
return widget.emptyWidget;
return const AliceEmptyLogsWidget();
}

final List<AliceLog> filteredLogs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ class AliceLogsScreen extends StatelessWidget {
? AliceRawLogListWidget(
scrollController: scrollController,
getRawLogs: aliceLogger?.getAndroidRawLogs(),
emptyWidget: const AliceEmptyLogsWidget(),
)
: AliceLogListWidget(
logsStream: aliceLogger?.logsStream,
scrollController: scrollController,
emptyWidget: const AliceEmptyLogsWidget(),
)
: const AliceEmptyLogsWidget();
}
Loading

0 comments on commit ed56220

Please sign in to comment.