Files
MrbWebLibre/app/lib/features/web_view/presentation/controllers/readerability.dart
T
2024-07-12 10:59:18 +02:00

34 lines
974 B
Dart

import 'package:bang_navigator/features/web_view/presentation/services/readerability_script.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'readerability.g.dart';
@Riverpod()
class ReaderabilityController extends _$ReaderabilityController {
late ReaderabilityScriptService _service;
@override
FutureOr<void> build(InAppWebViewController? controller) async {
_service =
ref.watch(readerabilityScriptServiceProvider(controller).notifier);
}
Future<bool> isReaderable() async {
state = const AsyncLoading();
final result = await AsyncValue.guard(() async {
return await _service.isReaderable();
});
state = result;
return result.valueOrNull ?? false;
}
Future<void> applyReaderable() async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
await _service.applyReaderable();
});
}
}