interactive_builder 0.1.2 copy "interactive_builder: ^0.1.2" to clipboard
interactive_builder: ^0.1.2 copied to clipboard

InteractiveBuilder to handle deactivated, hovered, pressed, states

Interactive Builder #

A Flutter widget that simplifies building interactive UI elements by providing the current interaction state to its builder.

Features #

  • Easy to Use: Simply wrap your widget with InteractiveBuilder and use the provided state to customize your UI.
  • Declarative State Handling: Easily define UI for different interaction states (hover, press, deactivate) in a clean and readable way using state.resolve.
  • Flexible: Can be used to create a wide variety of interactive widgets.

Usage #

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

...
    InteractiveBuilder(
      onTap: () {
        print('Tapped!');
      },
      builder: (context, state, child) => Container(
        decoration: BoxDecoration(
          color: state.resolve(
            Colors.blue,
            hovered: Colors.lightBlue,
            pressed: Colors.blueAccent,
            deactivated: Colors.grey,
          ),
        ),
        child: const Text('Click Me'),
      ),
    )
...

InteractionState #

The InteractionState has a resolve method to easily choose a value based on the current state.

resolve<T> #

The resolve method takes a default value and optional values for hovered, pressed, and deactivated states. It returns the value that corresponds to the current state.

The deactivated state is triggered when the onTap callback is null.

Container(
    color: state.resolve(
        Colors.blue, // Default color
        hovered: Colors.lightBlue,
        pressed: Colors.blueAccent,
        deactivated: Colors.grey,
    ),
    child: const Text('Click Me'),
)
6
likes
0
points
12
downloads

Publisher

verified publisherflutter.sskplay.com

Weekly Downloads

InteractiveBuilder to handle deactivated, hovered, pressed, states

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on interactive_builder