30 lines
679 B
Dart
30 lines
679 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
class DemoState {
|
|
const DemoState({this.count = 0, this.query = ''});
|
|
|
|
final int count;
|
|
final String query;
|
|
|
|
DemoState copyWith({int? count, String? query}) {
|
|
return DemoState(count: count ?? this.count, query: query ?? this.query);
|
|
}
|
|
}
|
|
|
|
class DemoController extends Notifier<DemoState> {
|
|
@override
|
|
DemoState build() => const DemoState();
|
|
|
|
void increment() {
|
|
state = state.copyWith(count: state.count + 1);
|
|
}
|
|
|
|
void updateQuery(String query) {
|
|
state = state.copyWith(query: query);
|
|
}
|
|
}
|
|
|
|
final demoControllerProvider = NotifierProvider<DemoController, DemoState>(
|
|
DemoController.new,
|
|
);
|