Base Flutter widget which triggers rebuild only of props changed

Overview

pure_widget

lesnitsky.dev GitHub stars Twitter Follow

Base widget which triggers rebuild only if props changed

Installation

pubspec.yaml:

dependencies:
  pure_widget: ^1.0.0

Example

import 'dart:math';

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

void main() {
  runApp(App());
}

class TileProps {
  final int value;

  TileProps(this.value);
}

class Tile extends PureWidget<TileProps> {
  final TileProps props;

  const Tile({Key? key, required this.props}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    print('rebuild with new value ${props.value}');

    return Card(
      child: Center(
        child: Text(
          props.value.toString(),
          style: Theme.of(context).textTheme.headline1,
        ),
      ),
    );
  }
}

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  final List<TileProps> values = [TileProps(0), TileProps(0), TileProps(0)];
  final r = Random();

  update() {
    setState(() {
      final index = r.nextInt(3);
      final oldValue = values[index].value;

      values[index] = TileProps(oldValue + 1);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Column(
          children: [
            ...[
              Tile(props: values[0]),
              Tile(props: values[1]),
              Tile(props: values[2]),
            ].map((e) => Expanded(child: e))
          ],
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: update,
        ),
      ),
    );
  }
}

License

MIT

You might also like...

A COVID-19 case tracker app which basically fetches latest data from an API and display it beautifully according to countries.

A COVID-19 case tracker app which basically fetches latest data from an API and display it beautifully according to countries.

Stay Safe Coronavirus Tracker Flutter App This app basically tracks the total cases of infected persons (real-time data), in all countries with total

Jun 20, 2022

A draggable Flutter widget that makes implementing a SlidingUpPanel much easier!

A draggable Flutter widget that makes implementing a SlidingUpPanel much easier!

sliding_up_panel A draggable Flutter widget that makes implementing a SlidingUpPanel much easier! Based on the Material Design bottom sheet component,

Jan 7, 2023

Circular Reveal Animation as Flutter widget!

Circular Reveal Animation as Flutter widget!

Circular Reveal Animation Circular Reveal Animation as Flutter widget! Inspired by Android's ViewAnimationUtils.createCircularReveal(...). Статья с оп

Aug 15, 2022

A Flutter Package providing Avatar Glow Widget

A Flutter Package providing Avatar Glow Widget

Avatar Glow This Flutter package provides a Avatar Glow Widget with cool background glowing animation. Live Demo: https://apgapg.github.io/avatar_glow

Dec 22, 2022

✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web

✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web

Flutter EasyLoading English | 简体中文 Live Preview 👉 https://nslog11.github.io/flutter_easyloading Installing Add this to your package's pubspec.yaml fi

Jan 9, 2023

A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.

A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.

Motion Tab Bar A beautiful animated widget for your Flutter apps Preview: | | Getting Started Add the plugin: dependencies: motion_tab_bar: ^0.1.5 B

Nov 15, 2022

a widget provided to the flutter scroll component drop-down refresh and pull up load.

a widget provided to the flutter scroll component drop-down refresh and pull up load.

flutter_pulltorefresh Intro a widget provided to the flutter scroll component drop-down refresh and pull up load.support android and ios. If you are C

Jan 5, 2023

Highly customizable, feature-packed calendar widget for Flutter

Highly customizable, feature-packed calendar widget for Flutter

TableCalendar Highly customizable, feature-packed calendar widget for Flutter. TableCalendar with custom styles TableCalendar with custom builders Fea

Jan 7, 2023

Flutter 3D Flip Animation Widget

Flutter 3D Flip Animation Widget

flutter_flip_view This is a flutter Widget base on pure Dart code that provides 3D flip card visuals. Usage add package in your pubspec.yaml dependenc

Dec 30, 2022
Owner
Andrei Lesnitsky
Open Source Software Engineer @invertase
Andrei Lesnitsky
This flutter package contains a widget called DecodingTextEffect which is having some cool Decode Effects for texts.

This flutter package contains a widget called DecodingTextEffect which is having some cool Decode Effects for texts. Installing 1. Depend on it Add th

Aadarsh Patel 13 Nov 25, 2020
A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations.

A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations.

HeavenOSK 97 Jan 6, 2023
A Flutter widget that easily adds the flipping animation to any widget

flip_card A component that provides a flip card animation. It could be used for hiding and showing details of a product. How to use import 'package:fl

Bruno Jurković 314 Dec 31, 2022
A widget that allow user resize the widget with drag

Flutter-Resizable-Widget A widget that allow user resize the widget with drag Note: this widget uses Getx Example bandicam.2021-11-11.12-34-41-056.mp4

MohammadAminZamani.afshar 22 Dec 13, 2022
A flutter package which makes it easier to display the difference between two images.

?? Before After A flutter package which makes it easier to display the differences between two images.. The source code is 100% Dart, and everything r

Sahil Kumar 741 Dec 30, 2022
A flutter package which will help you to generate pin code fields with beautiful design and animations

A flutter package which will help you to generate pin code fields with beautiful design and animations. Can be useful for OTP or pin code inputs ?? ??

Adar 550 Dec 23, 2022
Sample Flutter Drawing App which allows the user to draw onto the canvas along with color picker and brush thickness slider.

DrawApp Sample Flutter Drawing App which allows the user to draw onto the canvas along with color picker and brush thickness slider. All code free to

Jake Gough 226 Nov 3, 2022
A flutter package which display the library collapse according to the number of images associated with hero animation

?? Gallery Collapse A flutter package which display the library collapse accordi

null 6 Sep 12, 2022
filterList is a flutter package which provide utility to search/filter data from provided dynamic list.

filter_list Plugin FilterList is a flutter package which provide utility to search/filter on the basis of single/multiple selection from provided dyna

Sonu Sharma 156 Dec 24, 2022
A flutter package which contains a collection of some cool and beautiful effects; support android and ios

flutter effects A flutter package which contains a collection of some cool and beautiful effects; support android and ios . Screenshot type support ch

大海豚 462 Jan 3, 2023