2024-07-18 12:41:40 +03:30
|
|
|
|
2024-07-14 18:57:07 +03:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
import 'package:riverpod_flutter_tuts/outerapi/auth/call/getRandomData.dart';
|
|
|
|
|
|
|
|
|
|
import '../../outerapi/auth/model/my_random.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The homepage of our application
|
|
|
|
|
class RandomWidget extends StatelessWidget {
|
|
|
|
|
const RandomWidget({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Consumer(
|
|
|
|
|
builder: (context, ref, child) {
|
|
|
|
|
|
|
|
|
|
final AsyncValue<MyRandom> myRandom = ref.watch(getMyRandomProvider);
|
|
|
|
|
|
2024-07-18 12:41:40 +03:30
|
|
|
return Row( children: <Widget>[
|
|
|
|
|
Center(
|
|
|
|
|
child: switch (myRandom) {
|
|
|
|
|
AsyncData(:final MyRandom value ) => Text(
|
|
|
|
|
'myRandom: $value'
|
|
|
|
|
),
|
|
|
|
|
AsyncError() => const Text('Oops, something unexpected happened'),
|
|
|
|
|
_ => const CircularProgressIndicator(),
|
2024-07-14 18:57:07 +03:30
|
|
|
|
2024-07-18 12:41:40 +03:30
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
ref.invalidate(getMyRandomProvider);
|
|
|
|
|
},
|
2024-07-20 12:53:59 +03:30
|
|
|
child: const Text("Refresh ME"),
|
2024-07-18 12:41:40 +03:30
|
|
|
),
|
|
|
|
|
]
|
2024-07-14 18:57:07 +03:30
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|