An open API service indexing awesome lists of open source software.

https://github.com/hantrungkien/cached-widget

Avoid unnecessary rebuilding of Flutter Widgets. Only rebuild when the Widget's data changes.
https://github.com/hantrungkien/cached-widget

cached-widget flutter rebuild

Last synced: 3 months ago
JSON representation

Avoid unnecessary rebuilding of Flutter Widgets. Only rebuild when the Widget's data changes.

Awesome Lists containing this project

README

          

Cached Widget

Avoid unnecessary rebuilding of Flutter Widgets. Only rebuild when the Widget's data changes.




Platform


Pub Package


License: MIT




# Installing

### 1. Depend on it

Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
cached_widget: ^1.0.0
```

### 2. Install it

You can install packages from the command line:

with `pub`:

```
$ pub get
```

with `Flutter`:

```
$ flutter pub get
```

### 3. Import it

Now in your `Dart` code, you can use:

```dart
import 'package:cached_widget/cached_widget.dart';
```

# Usage

## Primitive

```dart
class PrimitiveExample extends StatelessWidget {
const PrimitiveExample({super.key});

@override
Widget build(BuildContext context) {
return CachedWidget(
value: "String",
builder: (context, value) {
return const SizedBox.shrink();
},
);
}
}
```

## Collection

```dart
class ListExample extends StatelessWidget {
const ListExample({super.key});

@override
Widget build(BuildContext context) {
return CachedWidget(
value: const ['1', '2', '3'],
builder: (context, value) {
return const SizedBox.shrink();
},
);
}
}
```

## Object

>Object class must be extended from Equatable or use Freeze to implement the equals and hashCode functions for diffing.

```dart
import 'package:equatable/equatable.dart';

class ObjectDemo extends Equatable {
final String id;
final List skins;

const ObjectDemo({
required this.id,
required this.skins,
});

@override
List get props => [id, skins];
}

class ObjectExample extends StatelessWidget {
const ObjectExample({super.key});

@override
Widget build(BuildContext context) {
return CachedWidget(
value: const ObjectDemo(id: '1', skins: ['1', '2', '3']),
builder: (context, value) {
return const SizedBox.shrink();
},
);
}
}
```