我有一个登录屏幕,我希望可以在整个应用程序的不同位置访问它。我可以使用该屏幕作为像这样的模态底部吗?
答案 0 :(得分:0)
是的,你可以,下面的代码片段用于显示底部:-
bottomSheetForSignIn(BuildContext context)
{
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(25),topRight: Radius.circular(25)),
),
isScrollControlled: true,
context: context,
builder: (context){
return SignIn();
}
);
}
然后创建一个有状态的小部件登录,返回一个具有属性高度的容器(以控制要显示底部工作表的屏幕部分)
它的代码如下:-
class SignIn extends StatefulWidget {
const SignIn({Key? key}) : super(key: key);
@override
_SignInState createState() => _SignInState();
}
class _SignInState extends State<SignIn> {
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height*0.9,//to control height of bottom sheet
child: Column( //your design from here onwards
children: [
],
),
);
}
}
无论何时您想打开底部工作表,只需拨打以下电话:-
bottomSheetForSignIn(context);