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.
- Host: GitHub
- URL: https://github.com/hantrungkien/cached-widget
- Owner: hantrungkien
- License: mit
- Created: 2024-08-23T13:58:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-23T14:20:14.000Z (about 1 year ago)
- Last Synced: 2025-02-23T14:22:30.378Z (8 months ago)
- Topics: cached-widget, flutter, rebuild
- Language: Dart
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Cached Widget
Avoid unnecessary rebuilding of Flutter Widgets. Only rebuild when the Widget's data changes.
# 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();
},
);
}
}
```