我想导航到一个新页面(从页面A到页面B),其中页面B将从底部移动到顶部。
第A页
Navigator.pushNamed(context, InvoiceRoutes.createInvoiceScreen.dart);
- 酒店
class InvoiceRoutes {
static const createInvoiceScreen = "/createInvoiceScreen";
static MaterialPageRoute<dynamic> _createInvoiceScreenRoute() {
return MaterialPageRoute(builder: (context) {
return BlocProvider(
create: (_) => sl<OwnerInvoiceListCubit>(),
child: BottomToTopPageRoute(page: PageB()));
});
}
Route<dynamic>? getRoutes(RouteSettings settings) {
if (settings.name == createInvoiceScreen) {
return _createInvoiceScreenRoute();
}
return null;
}
}
自下而上的页面路线
import 'package:flutter/material.dart';
class BottomToTopPageRoute<T> extends PageRouteBuilder<T> {
final Widget page;
BottomToTopPageRoute({required this.page})
: super(
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.fastOutSlowIn;
var tween =
Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
var offsetAnimation = animation.drive(tween);
return SlideTransition(
position: offsetAnimation,
child: child,
);
},
);
}
错误
无法将参数类型“BottomToTopPageRoute”分配给参数类型“Widget?'
1条答案
按热度按时间q9yhzks01#
出现此错误是因为您正在使用PageRouteBuilder代替小部件。不需要MaterialPageRoute,因为您正在使用PageRouteBuilder。
将函数
_createInvoiceScreenRoute()
替换为希望有帮助。