36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:riverpod_flutter_tuts/widgets/notifier/counter.dart';
|
|
import 'package:riverpod_flutter_tuts/widgets/notifier/random.dart';
|
|
|
|
|
|
class Random3Widget extends ConsumerWidget {
|
|
const Random3Widget({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
// TODO: implement build
|
|
|
|
var myRandom = ref.watch(randomNotifProvider);
|
|
return Row(
|
|
children: [
|
|
Center(
|
|
child: switch (myRandom) {
|
|
AsyncData(:final value ) => Text(
|
|
'data: $value'
|
|
),
|
|
AsyncError() => const Text('Oops, something unexpected happened'),
|
|
_ => const CircularProgressIndicator(),
|
|
}),
|
|
!myRandom.isLoading ? ElevatedButton(onPressed:() {
|
|
if (!myRandom.isLoading)
|
|
ref.read(randomNotifProvider.notifier).again();
|
|
}, child: Text(myRandom.isLoading ? "wait":"new"))
|
|
:
|
|
const Text("loading")
|
|
,
|
|
]
|
|
);
|
|
}
|
|
} |