Skip to content

Commit

Permalink
fix: add log for more details
Browse files Browse the repository at this point in the history
  • Loading branch information
evan361425 committed Jun 22, 2024
1 parent c06d988 commit 7eba56f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
4 changes: 3 additions & 1 deletion lib/src/configs/spotlight_backdrop_config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';

import '../spotlight_ant.dart';
Expand All @@ -13,7 +15,7 @@ class SpotlightBackdropConfig {
/// Return null to do nothing.
///
/// Default using: [SpotlightAntAction.next]
final Future<SpotlightAntAction?> Function()? onTap;
final FutureOr<SpotlightAntAction?> Function()? onTap;

/// Using [InkWell] or [GestureDetector] on backdrop.
final bool usingInkwell;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/configs/spotlight_config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';

import '../spotlight_ant.dart';
Expand Down Expand Up @@ -29,7 +31,7 @@ class SpotlightConfig {
/// Return null to do nothing.
///
/// Default using: [SpotlightAntAction.next]
final Future<SpotlightAntAction?> Function()? onTap;
final FutureOr<SpotlightAntAction?> Function()? onTap;

/// Using [InkWell] or [GestureDetector] on spotlight.
final bool usingInkwell;
Expand Down
7 changes: 4 additions & 3 deletions lib/src/spotlight_ant.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -102,7 +103,7 @@ class SpotlightAnt extends StatefulWidget {
}

class SpotlightAntState extends State<SpotlightAnt> {
/// If this ant required to be monitored([SpotlightAnt.monitorId] has set),
/// If this ant required to be monitored ([SpotlightAnt.monitorId] has set),
/// it might be paused to be shown.
bool paused = false;

Expand All @@ -120,7 +121,7 @@ class SpotlightAntState extends State<SpotlightAnt> {
paused = false;
SpotlightShow.maybeOf(context)?.start();

// avoid edit callback collection in callback
// avoid edit visibility's callback collection in callback itself
await Future.delayed(Duration.zero);
VisibilityDetectorController.instance.forget(key);
}
Expand Down Expand Up @@ -216,7 +217,7 @@ enum SpotlightAntAction {
skip,
finish;

Future<SpotlightAntAction?> meOr(Future<SpotlightAntAction?> Function()? cb) async {
FutureOr<SpotlightAntAction?> meOr(FutureOr<SpotlightAntAction?> Function()? cb) async {
return cb == null ? this : await cb();
}
}
19 changes: 10 additions & 9 deletions lib/src/spotlight_gaffer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta
if (!currentAnt!.widget.spotlight.silent) {
child = currentAnt!.widget.spotlight.usingInkwell
? InkWell(
key: const Key('evan'),
borderRadius: BorderRadius.circular(builder.inkwellRadius(r)),
splashColor: currentAnt!.widget.spotlight.splashColor,
onTap: _onSpotlightTap,
Expand Down Expand Up @@ -263,7 +262,7 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta

/// Go to next spotlight properly.
void next() {
if (SpotlightAnt.debug) log('[ant] performing next');
if (SpotlightAnt.debug) log('performing next', name: 'ant');
if (currentIndex < widget.ants.length - 1) {
_startZoomOut().then((success) {
if (success) {
Expand All @@ -285,7 +284,7 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta

/// Go to previous spotlight properly.
void prev() {
if (SpotlightAnt.debug) log('[ant] performing prev');
if (SpotlightAnt.debug) log('performing prev', name: 'ant');
if (currentIndex > 0) {
_startZoomOut().then((success) {
if (success) {
Expand All @@ -301,7 +300,7 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta
/// but won't call the [SpotlightGaffer.onSkip].
void finish() {
_startZoomOut().then((success) {
if (SpotlightAnt.debug) log('[ant] execute finish callback');
if (SpotlightAnt.debug) log('execute finish callback', name: 'ant');
widget.onFinish();
});
}
Expand All @@ -312,7 +311,7 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta
/// but won't call the [SpotlightGaffer.onFinish].
void skip() {
_startZoomOut().then((success) {
if (SpotlightAnt.debug) log('[ant] execute skip callback');
if (SpotlightAnt.debug) log('execute skip callback', name: 'ant');
widget.onSkip();
});
}
Expand Down Expand Up @@ -342,14 +341,14 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta
void _onBackdropTap() async {
final act = await SpotlightAntAction.next.meOr(currentAnt?.widget.backdrop.onTap);

if (SpotlightAnt.debug) log('[ant] backdrop tapped for $act');
if (SpotlightAnt.debug) log('backdrop tapped for $act', name: 'ant');
perform(act);
}

void _onSpotlightTap() async {
final act = await SpotlightAntAction.next.meOr(currentAnt?.widget.spotlight.onTap);

if (SpotlightAnt.debug) log('[ant] spotlight tapped for $act');
if (SpotlightAnt.debug) log('spotlight tapped for $act', name: 'ant');
perform(act);
}

Expand All @@ -362,10 +361,12 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta

// abort this show if some actors are being paused
if (currentAnt!.paused) {
if (SpotlightAnt.debug) log('paused at $index', name: 'ant');
widget.onPaused(index);
return;
}

if (SpotlightAnt.debug) log('start zoom in', name: 'ant');
setState(() {
final ant = currentAnt!.widget;
_zoomController.duration = ant.duration.zoomIn;
Expand All @@ -388,7 +389,7 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta

// Start animation
_zoomController.forward().then((value) {
if (SpotlightAnt.debug) log('[ant] ready to bump');
if (SpotlightAnt.debug) log('finish zoom in, start to bump', name: 'ant');
isBumping = true;
if (antMounted) {
currentAnt!.widget.onShown?.call();
Expand All @@ -407,7 +408,7 @@ class SpotlightGafferState extends State<SpotlightGaffer> with TickerProviderSta

Future<bool> _startZoomOut() async {
if (isBumping) {
if (SpotlightAnt.debug) log('[ant] finish the bump');
if (SpotlightAnt.debug) log('finish the bump', name: 'ant');
isBumping = false;
currentAnt!.widget.onDismiss?.call();
_bumpController.stop();
Expand Down
10 changes: 5 additions & 5 deletions lib/src/spotlight_show.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class SpotlightShowState extends State<SpotlightShow> {
);
});
Overlay.of(context).insert(_overlayEntry!);
if (SpotlightAnt.debug) log('[ant] started the show');
if (SpotlightAnt.debug) log('started the show', name: 'ant');
}
});
}
Expand All @@ -299,7 +299,7 @@ class SpotlightShowState extends State<SpotlightShow> {
/// Register [SpotlightAnt] programmatically.
void register(SpotlightAntState ant) {
if (!_antQueue.contains(ant)) {
if (SpotlightAnt.debug) log('[ant] registered $ant');
if (SpotlightAnt.debug) log('registered $ant', name: 'ant');
_queue(ant);
}
}
Expand All @@ -311,7 +311,7 @@ class SpotlightShowState extends State<SpotlightShow> {
final success = _antQueue.remove(ant);

if (success) {
if (SpotlightAnt.debug) log('[ant] unregister $ant');
if (SpotlightAnt.debug) log('unregister $ant', name: 'ant');
_dequeue(ant);
}
}
Expand All @@ -330,7 +330,7 @@ class SpotlightShowState extends State<SpotlightShow> {
}

if (isReadyToStart && widget.startWhenReady) {
if (SpotlightAnt.debug) log('[ant] ready to start the show');
if (SpotlightAnt.debug) log('ready to start the show', name: 'ant');
final future = widget.showWaitFuture ?? Future.delayed(Duration.zero);
future.then((value) => start());
}
Expand All @@ -340,7 +340,7 @@ class SpotlightShowState extends State<SpotlightShow> {
_antQueue.removeWhere((e) => e == ant);

if (_antQueue.isEmpty) {
if (SpotlightAnt.debug) log('[ant] the show is finish');
if (SpotlightAnt.debug) log('the show is finish', name: 'ant');
_removeOverlayEntry();
}
}
Expand Down

0 comments on commit 7eba56f

Please sign in to comment.