返回 Skill 列表
extension
分类: 开发与工程无需 API Key

oref

关于使用Oref Flutter信号/状态管理库及其DevTools/分析器工具的指南。在回答有关安装Oref、创建信号/计算/效果、异步数据、反应式集合、SignalBuilder用法、分析器提示、DevTools扩展设置/使用或解决Oref行为问题时,请参考本指南。

person作者: jakexiaohubgithub

Oref

Based on the Oref docs and repository examples. Use BuildContext-bound APIs inside widget builds when possible.

Preferences

  • Match the user's language.
  • Prefer concise, runnable snippets over long explanations.
  • Use signal(context, ...)/computed(context, ...)/effect(context, ...) inside build.
  • Use null context only outside widgets, and keep the dispose handle.
  • Use SignalBuilder to scope rebuilds to small subtrees.
  • Use batch() for multi-step updates or collection mutations.
  • Avoid writing to signals inside computed getters.
  • Call hooks unconditionally at the top level of a build scope.

Core

| Topic | Description | Reference | | ----------------- | --------------------------------------------------------------------------- | ------------------------------------------------ | | Quick Start | Install + minimal signal/computed/effect usage | quick-start | | Reactivity Core | Signals, computed, writableComputed, effects, batch, untrack, SignalBuilder | core-api | | Hooks & Lifecycle | Hook ordering rules, onMounted/onUnmounted, cleanup | hooks-lifecycle | | Async Data | useAsyncData lifecycle and rendering | async-data | | Collections | ReactiveList/Map/Set patterns | collections |

Tooling

| Topic | Description | Reference | | --------------- | ------------------------------- | ------------------------------------------------ | | Analyzer Lints | Plugin setup + lint catalog | analyzer-lints | | DevTools | Extension setup + runtime notes | devtools | | Troubleshooting | Common pitfalls and fixes | troubleshooting |

Quick Reference

Minimal widget

import 'package:flutter/material.dart';
import 'package:oref/oref.dart';

class Counter extends StatelessWidget {
  const Counter({super.key});

  @override
  Widget build(BuildContext context) {
    final count = signal(context, 0);
    final doubled = computed(context, (_) => count() * 2);

    return Column(
      children: [
        Text('Count: ${count()} / ${doubled()}'),
        TextButton(onPressed: () => count.set(count() + 1), child: const Text('Add')),
      ],
    );
  }
}

Key imports

import 'package:oref/oref.dart';

Response workflow

  1. Identify the question type and open the matching reference.
  2. Provide the smallest snippet that answers the question.
  3. Ask for missing context only if required (Flutter version, target platform, existing code).
  4. Avoid guessing versions; read the user's pubspec.yaml or ask them to confirm.