【发布时间】:2020-10-26 12:09:08
【问题描述】:
我想在第一个屏幕上按下按钮时显示第二个屏幕。为此,我正在使用navigation.push。直到我在第二个屏幕布局的行小部件中添加一个容器小部件之前,它都可以正常工作。当我删除它时,它工作正常。谁能告诉我我在这里做错了什么? 这是我第二个屏幕的代码
import 'package:flutter/material.dart';
class NewScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.white,
padding: EdgeInsets.only(top: 50.0, bottom: 60.0),
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(200.0),
child: Image.asset(
'assets/images/test.png',
height: 200.0,
width: 200.0,)
),
SizedBox(height: 20.0,),
Text(
'Remote User',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 25),
),
SizedBox(height: 20.0,),
Text(
'Incoming Call',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 15),
),
SizedBox(height: 120.0,),
Row(
children: <Widget>[
//when I add single container it works fine
Container(
height: 70.0,
width: 70.0,
child: FittedBox(
child: FloatingActionButton(
onPressed: () {},
elevation: 20.0,
//shape: CircleBorder(side: BorderSide(color: Colors.red)),
mini: false,
child: Icon(
Icons.call,
color: Colors.white,
),
backgroundColor: Colors.green,
),
),
),
// this widget cause blank screen
Container(
height: 70.0,
width: 70.0,
child: FittedBox(
child: FloatingActionButton(
onPressed: () {},
elevation: 20.0,
//shape: CircleBorder(side: BorderSide(color: Colors.red)),
mini: false,
child: Icon(
Icons.call,
color: Colors.white,
),
backgroundColor: Colors.green,
),
),
),
],
),
]
),
),
);
}
}
这里是第一屏的代码:
class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Center(
child: RaisedButton(
child: Text('Second Screen'),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => NewScreen()),);
},
),
),
);
}
}
【问题讨论】:
-
遇到相同问题的任何人请访问此帖子,它可能会有所帮助。 stackoverflow.com/questions/54017447/…
标签: flutter dart flutter-layout