12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import 'package:flutter/material.dart';
- /// 万物皆可Notifier
- extension ObjectNotifierExt on Object? {
- ValueNotifier<T> notifier<T>() => ValueNotifier(this as T);
- }
- /// 拓展ValueNotifier
- /// 快捷调用builder来编写组件
- extension NotifierObjectExt<T> on ValueNotifier<T> {
- /// 创建Builder
- ValueListenableBuilder<T> builder(Widget Function(T v) build) {
- return ValueListenableBuilder<T>(
- valueListenable: this,
- builder: (context, v, child) => build.call(v),
- );
- }
- /// ==
- bool equals(T other) => value == other;
- /// 刷新数据
- update(T other) => value = other;
- }
- /// num相关拓展
- extension NotifierNumExt on ValueNotifier<num> {
- ValueListenableBuilder<num> builder(Widget Function(num v) build) {
- return ValueListenableBuilder(
- valueListenable: this,
- builder: (context, v, child) => build.call(v),
- );
- }
- num operator +(num other) => value += other;
- num operator -(num other) => value -= other;
- num operator *(num other) => value *= other;
- double operator /(num other) => value = value / other;
- int operator ~/(num other) => value = value ~/ other;
- num operator -() => -value;
- /// 取模
- num operator %(num other) => value % other;
- /// 取余
- num remainder(num other) => value.remainder(other);
- /// 是否相等
- bool equals(num other) => value == other;
- bool operator <(num other) => value < other;
- bool operator <=(num other) => value <= other;
- bool operator >(num other) => value > other;
- bool operator >=(num other) => value >= other;
- /// 赋值 通知更新
- update(num other) => value = other;
- }
|