passsy / use-context-plusr4
Use package:context_plus
PublicUse package:context_plus to bind objects to widget scopes and watch them, instead of provider, riverpod, get_it or hand-written InheritedWidgets.
tests, run by the registry8 passed · slowest 7.9 ms
- The advice links to pub.dev
✓fires4.1 ms
fires on a hand-written InheritedWidget
write lib/cart_scope.dartfired: line 1
class CartScope extends InheritedWidget {
const CartScope({required this.cart, required super.child, super.key});
final Cart cart;
}✓quiet2.9 ms
stays quiet on a context_plus Ref
write lib/cart.dartstayed quiet
final _cartRef = Ref<Cart>();
✓quiet3.1 ms
stays quiet on an InheritedWidget the edit did not touch
write lib/cart_scope.dart · wrote line 3stayed quiet
class CartScope extends InheritedWidget {
const CartScope({required this.cart, required super.child, super.key});
final Cart cart;
}✓skips0.0 ms
stays quiet when the agent only reads the file
read lib/cart_scope.dartno handler of the detector wants this event
class CartScope extends InheritedWidget {
const CartScope({required this.cart, required super.child, super.key});
final Cart cart;
}✓skips0.0 ms
stays quiet in a test file
write test/cart_scope_test.dartno handler of the detector wants this event
class CartScope extends InheritedWidget {
const CartScope({required this.cart, required super.child, super.key});
final Cart cart;
}✓fires6.4 ms
points at the principle when the user mentions dependency injection in a Dart project
prompt · in fixtures/dart_appfired: "dependency injection"
How should we do dependency injection for the cart?✓quiet4.5 ms
stays quiet outside a Dart project
promptstayed quiet
How should we do dependency injection for the cart?✓quiet7.9 ms
stays quiet on a prompt about something else
prompt · in fixtures/dart_appstayed quiet
Add a checkout button to the cartdetector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";
const scope = source`
class CartScope extends InheritedWidget {
const CartScope({required this.cart, required super.child, super.key});
final Cart cart;
}
`;
test("fires on a hand-written InheritedWidget", () => {
expect(detect(write("lib/cart_scope.dart", scope))).toEqual([{ line: 1 }]);
});
test("stays quiet on a context_plus Ref", () => {
expect(detect(write("lib/cart.dart", "final _cartRef = Ref<Cart>();\n"))).toEqual([]);
});
test("stays quiet on an InheritedWidget the edit did not touch", () => {
expect(detect(edit("lib/cart_scope.dart", scope, { written: " final Cart cart;" }))).toEqual([]);
});
test("stays quiet when the agent only reads the file", () => {
expect(detect(read("lib/cart_scope.dart", scope))).toEqual([]);
});
test("stays quiet in a test file", () => {
expect(detect(write("test/cart_scope_test.dart", scope))).toEqual([]);
});
const dartApp = { project: "fixtures/dart_app" };
test("points at the principle when the user mentions dependency injection in a Dart project", () => {
expect(detect(prompt("How should we do dependency injection for the cart?"), dartApp)).toEqual([{ match: "dependency injection", depth: "pointer" }]);
});
test("stays quiet outside a Dart project", () => {
expect(detect(prompt("How should we do dependency injection for the cart?"))).toEqual([]);
});
test("stays quiet on a prompt about something else", () => {
expect(detect(prompt("Add a checkout button to the cart"), dartApp)).toEqual([]);
});