Skip to main content

UndoHistory

Struct UndoHistory 

Source
pub struct UndoHistory<T: Clone + PartialEq + 'static, V: ValueListenable<T> + Clone + PartialEq + 'static = Ref<ValueNotifier<T>>> {
    pub key: Option<KeyRef>,
    pub should_change_undo_stack: Option<ShouldChangeUndoStack<T>>,
    pub value: V,
    pub on_triggered: UndoHistoryOnTriggered<T>,
    pub focus_node: FocusNodeRef,
    pub undo_stack_modifier: Option<UndoStackModifier<T>>,
    pub controller: Option<Ref<UndoHistoryController>>,
    pub child: WidgetRef,
}
Expand description

Provides undo/redo capabilities for a ValueNotifier.

Listens to value and saves relevant values for undoing/redoing. The cadence at which values are saved is a best approximation of the native behaviors of a number of hardware keyboard on Flutter’s desktop platforms, as there are subtle differences between each of the platforms.

Listens to keyboard undo/redo shortcuts and calls on_triggered when a shortcut is triggered that would affect the state of the value.

The child must manage focus on the focus_node. For example, using a TextField or Focus widget.

The value is any kept ValueListenable, which Dart types as a ValueNotifier<T>: a Ref<ValueNotifier<T>>, or a TextEditingControllerRef.

Fields§

§key: Option<KeyRef>§should_change_undo_stack: Option<ShouldChangeUndoStack<T>>

Called when checking whether a value change should be pushed onto the undo stack.

§value: V

The value to track over time.

§on_triggered: UndoHistoryOnTriggered<T>

Called when an undo or redo causes a state change.

If the state would still be the same before and after the undo/redo, this will not be called. For example, receiving a redo when there is nothing to redo will not call this method.

Changes to the value while this method is running will not be recorded on the undo stack. For example, a TextInputFormatter may change the value from what was on the undo stack, but this new value will not be recorded, as that would wipe out the redo history.

§focus_node: FocusNodeRef

The [FocusNode] that will be used to listen for focus to set the initial undo state for the element.

§undo_stack_modifier: Option<UndoStackModifier<T>>

Called right before a new entry is pushed to the undo stack.

The value returned from this method will be pushed to the stack instead of the original value.

If null then the original value will always be pushed to the stack.

§controller: Option<Ref<UndoHistoryController>>

Controls the undo state.

If null, this widget will create its own UndoHistoryController.

§child: WidgetRef

The child widget of UndoHistory.

Implementations§

Source§

impl<T: Clone + PartialEq + 'static, V: ValueListenable<T> + Clone + PartialEq + 'static> UndoHistory<T, V>

Source

pub fn new<K>( value: V, on_triggered: impl Fn(&mut App, T) + 'static, focus_node: FocusNodeRef, child: impl IntoWidget<K>, ) -> UndoHistory<T, V>

Creates an instance of UndoHistory.

Source

pub fn key(self, key: KeyRef) -> UndoHistory<T, V>

Dart UndoHistory(key:).

Source

pub fn should_change_undo_stack( self, should_change_undo_stack: impl Fn(Option<&T>, &T) -> bool + 'static, ) -> UndoHistory<T, V>

Dart UndoHistory(shouldChangeUndoStack:).

Source

pub fn undo_stack_modifier( self, undo_stack_modifier: impl Fn(T) -> T + 'static, ) -> UndoHistory<T, V>

Dart UndoHistory(undoStackModifier:).

Source

pub fn controller( self, controller: Ref<UndoHistoryController>, ) -> UndoHistory<T, V>

Dart UndoHistory(controller:).

Trait Implementations§

Source§

impl<T: Clone + PartialEq + 'static, V: ValueListenable<T> + Clone + PartialEq + 'static> Debug for UndoHistory<T, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone + PartialEq + 'static, V: ValueListenable<T> + Clone + PartialEq + 'static> StatefulWidget for UndoHistory<T, V>

Source§

type State = UndoHistoryState<T, V>

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> UndoHistoryState<T, V>

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl<T, V = Retained<Handle<ValueNotifier<T>>>> !RefUnwindSafe for UndoHistory<T, V>

§

impl<T, V = Retained<Handle<ValueNotifier<T>>>> !Send for UndoHistory<T, V>

§

impl<T, V = Retained<Handle<ValueNotifier<T>>>> !Sync for UndoHistory<T, V>

§

impl<T, V = Retained<Handle<ValueNotifier<T>>>> !UnwindSafe for UndoHistory<T, V>

§

impl<T, V> Forget for UndoHistory<T, V>

§

impl<T, V> Freeze for UndoHistory<T, V>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(Option<&T>, &T) -> bool> is !null: Freeze, PhantomData<RcInner<dyn Fn(Option<&T>, &T) -> bool>>: Freeze, V: Freeze, *const RcInner<dyn Fn(&mut App, T)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, T)>>: Freeze, NonZero<u32>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn Fn(T) -> T> is !null: Freeze, PhantomData<RcInner<dyn Fn(T) -> T>>: Freeze, PhantomData<fn() -> UndoHistoryController>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl<T, V> Move for UndoHistory<T, V>

§

impl<T, V> Unpin for UndoHistory<T, V>
where V: Unpin, Rc<dyn Key>: Unpin, Rc<dyn Fn(Option<&T>, &T) -> bool>: Unpin, Rc<dyn Fn(&mut App, T)>: Unpin, NonZero<u32>: Unpin, &'static FocusNodeVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn Fn(T) -> T>: Unpin, Rc<dyn Widget>: Unpin,

§

impl<T, V> UnsafeUnpin for UndoHistory<T, V>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(Option<&T>, &T) -> bool> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(Option<&T>, &T) -> bool>>: UnsafeUnpin, V: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, T)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, T)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn Fn(T) -> T> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(T) -> T>>: UnsafeUnpin, PhantomData<fn() -> UndoHistoryController>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>