When you run testWidgets in flutter_test.dart
errors_patch.dart is automatically opened and
Could not load source 'dart:core-patch/errors_patch.dart': <source not available>.
and the test fails with the statement.
widget_test.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:jintonic/data/subscription.dart';
import 'package:xxxxxxx/main.dart';
import 'package:xxxxxxx/view_pages/assets.dart';
import 'package:xxxxxxx/view_pages/config.dart';
import 'package:xxxxxxx/view_pages/title.dart';
void main() {
testWidgets('Route title page', (tester) async {
await tester.pumpWidget(const ProviderScope(child: MyApp()));
expect(find.byWidgetPredicate((widget) => widget is TitlePage),
findsOneWidget);
});
testWidgets('Tick action test', (tester) async {
await tester.pumpWidget(const ProviderScope(
child: MyApp()));
final BuildContext context = tester
.element(find.byWidgetPredicate((widget) => widget is TitlePage));
context.go('/assets');
await tester.pumpAndSettle();
expect(find.text('0'), findsOneWidget);
expect(find.text('10'), findsNothing);
await tester
.tap(find.byWidgetPredicate((widget) => widget is IconButton));
await tester.pump(const Duration(seconds: 10));
expect(find.text('10'), findsOneWidget);
expect(find.text('0'), findsNothing);
});
}
After examining the cases where errors occur and do not occur in the test, it was found that commenting out the following section would not result in an error.
import 'dart:async';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'subscription.freezed.dart';
final subscriptionProvider =
StateNotifierProvider<SubscriptionStateNotifier, SubscriptionState>((ref) {
return SubscriptionStateNotifier()
..init(tickerSubscriptionValue: DateTime.now());
});
final tickerSubscriptionValueProvider =
Provider((ref) => ref.watch(subscriptionProvider).tickerSubscriptionValue);
class SubscriptionStateNotifier extends StateNotifier<SubscriptionState> {
SubscriptionStateNotifier()
: super(SubscriptionState(tickerSubscriptionValue: DateTime.now()));
// final Ticker ticker = Ticker();
StreamSubscription<int>? tickerSubscription;
void init({required DateTime tickerSubscriptionValue}) =>
state = state.copyWith(tickerSubscriptionValue: tickerSubscriptionValue);
void tickerStart() {
tickerSubscription?.cancel();
// tickerSubscription = ticker.tick().listen((duration) {
// state = state.copyWith(tickerSubscriptionValue: DateTime.now());
// });
}
}
// class Ticker {
// Stream<int> tick() {
// return Stream.periodic(
// const Duration(seconds: 1),
// (x) => x,
// );
// }
// }
@freezed
abstract class SubscriptionState with _$SubscriptionState {
const factory SubscriptionState({required DateTime tickerSubscriptionValue}) =
_SubscriptionState;
}
Checked.
・Q&A about Could not load source 'dart:core-patch/errors_patch.dart': <source not available>.
-> Not found. Q&A about another file was found, but not helpful.
Could not load source 'dart:core/runtime/libobject_patch.dart': <source not available>
Reference Information
flutter doctor -v
[√] Flutter (Channel stable, 3.1.0-0.0.pre.745, on Microsoft Windows [Version 10.0.19044.1706], locale ja-JP)
• Flutter version 3.1.0-0.0.pre.745 at C:\Users\xxxxx\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c248854d17 (5 days ago), 2022-05-16 23:57:08 -0400
• Engine revision fce741dd83
• Dart version 2.18.0 (build 2.18.0-120.0.dev)
• DevTools version 2.13.1
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\xxxxx\AppData\Local\Android\Sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Android Studio (version 4.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.67.2)
• VS Code at C:\Users\xxxxxx\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.40.0
[√] Connected device (1 available)
• AOSP on IA Emulator (mobile) • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Best regards, please!