30 lines
536 B
Dart
30 lines
536 B
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
|
part 'counter.g.dart';
|
|
|
|
@riverpod
|
|
class CounterNotifier extends _$CounterNotifier {
|
|
|
|
int x = 0;
|
|
@override
|
|
Future<int> build() async{
|
|
return x;
|
|
}
|
|
|
|
void plus() {
|
|
x++;
|
|
ref.invalidateSelf();
|
|
// state = AsyncData(x);
|
|
}
|
|
|
|
void minus() {
|
|
x--;
|
|
// ref.invalidateSelf();
|
|
state = AsyncData(x);
|
|
}
|
|
}
|