my error said:
Exception has occurred.
_TypeError (type ‘(ProfileDataset) => SelfProfilePage’ is not a subtype of type ‘(dynamic) => Widget’)
my codes:
import 'package:flutter/material.dart';
class AwaitJumpPage<T> extends StatefulWidget {
const AwaitJumpPage({
super.key,
required this.future,
required this.callback,
});
final Future<T> future;
final Widget Function(T) callback;
@override
State<AwaitJumpPage> createState() => _AwaitJumpPageState<T>();
}
class _AwaitJumpPageState<T> extends State<AwaitJumpPage> {
@override
void initState() {
widget.future.then((value) {
if (mounted) {
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) {
// ignore: unnecessary_cast
final fun = widget.callback as Widget Function(dynamic);
return fun(value);
},
));
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
}
How I using this class:
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return AwaitJumpPage(
future: [[a future that return ProfileDataset]],
callback: (data){
return SelfProfilePage(data);
}
);
},
),
);
My class SelfProfilePage is a widget really.
Can you help me, please?
2
Answers
As I understand your final goal is crate something like that:
Pass generic type
ProfileDataset
while callingAwaitJumpPage