dreampad/lib/app/shared/helpers/deferred_router.dart

31 lines
708 B
Dart
Raw Permalink Normal View History

2023-11-28 10:44:58 +08:00
import 'package:flutter/material.dart';
class DeferredRouter extends StatelessWidget {
const DeferredRouter({
Key? key,
required this.future,
required this.builder,
}) : super(key: key);
final Future future;
final WidgetBuilder builder;
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: future,
builder: (context, snapshot) {
// web scene
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
}
return builder(context);
},
);
}
}