import 'package:flutter/material.dart'; /// 万物皆可Notifier extension ObjectNotifierExt on Object? { ValueNotifier notifier() => ValueNotifier(this as T); } /// 拓展ValueNotifier /// 快捷调用builder来编写组件 extension NotifierObjectExt on ValueNotifier { /// 创建Builder ValueListenableBuilder builder(Widget Function(T v) build) { return ValueListenableBuilder( 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 { ValueListenableBuilder 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; }