| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- class AsyncValueView<T> extends StatelessWidget {
- const AsyncValueView({
- super.key,
- required this.value,
- required this.data,
- this.loadingMessage = 'Loading...',
- });
- final AsyncValue<T> value;
- final Widget Function(T data) data;
- final String loadingMessage;
- @override
- Widget build(BuildContext context) {
- return value.when(
- data: data,
- loading: () => Card(
- child: Padding(
- padding: const EdgeInsets.all(20),
- child: Row(
- children: [
- const SizedBox(
- width: 18,
- height: 18,
- child: CircularProgressIndicator(strokeWidth: 2.2),
- ),
- const SizedBox(width: 12),
- Expanded(child: Text(loadingMessage)),
- ],
- ),
- ),
- ),
- error: (error, stackTrace) => Card(
- child: Padding(
- padding: const EdgeInsets.all(20),
- child: Text('Request failed: $error'),
- ),
- ),
- );
- }
- }
|