【发布时间】:2018-11-07 16:35:56
【问题描述】:
我一直在尝试制作一个颤振应用程序(仍在学习),并且能够制作一个登录屏幕。但是,我注意到该应用程序没有响应。当我在模拟器上测试它时,它工作正常,但是当我将它安装到一个屏幕较小的手机上时,我注意到小部件并不小,所以手机无法一次显示整个屏幕。有人可以帮我制作这个应用程序响应式,以便它适合任何尺寸的屏幕吗?
我的完整代码如下;
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
final TextEditingController _usernameController = new TextEditingController();
final TextEditingController _passwordController = new TextEditingController();
@override
Widget build(BuildContext context) {
void printSomething(){
print("Something was printed");
}
Widget buttonSection = new Container(
padding: new EdgeInsets.all(32.0),
child: new Row(
children: [
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new MaterialButton(
child: new Text(
"Sign In",
style: new TextStyle(
color: Colors.white,
fontSize: 20.0
),
),
onPressed: (){printSomething();},
height: 50.0,
minWidth: 400.0,
color: Colors.blueAccent,
),
SizedBox(height: 10.0),
new MaterialButton(
child: new Text(
"Sign Up",
style: new TextStyle(
color: Colors.white,
fontSize: 20.0
),
),
onPressed: null,
height: 50.0,
minWidth: 400.0,
color: Colors.blueAccent,
)
],
),
),
],
),
);
Widget textFieldSection = new Container(
padding: new EdgeInsets.all(32.0),
child: new Row(
children: [
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new TextField(
autocorrect: false,
obscureText: false,
controller: _usernameController,
maxLines: 1,
decoration: new InputDecoration(
hintText: "Username",
icon: new Icon(Icons.person),
),
style: new TextStyle(
fontSize: 20.0,
color: Colors.black
),
),
new SizedBox(height: 10.0),
new TextField(
autocorrect: false,
obscureText: true,
controller: _passwordController,
maxLines: 1,
decoration: new InputDecoration(
hintText: "Password",
icon: new Icon(Icons.vpn_key),
),
style: new TextStyle(
fontSize: 20.0,
color: Colors.black
),
),
],
),
),
],
),
);
Widget titleSection = new Container(
padding: new EdgeInsets.all(32.0),
child: new Row(
children: [
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new Container(
padding: const EdgeInsets.only(bottom: 8.0),
child: new Text(
"Please login using your credentials",
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
),
),
),
],
),
),
],
),
);
return new MaterialApp(
title: "Service",
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new Scaffold(
body: new ListView(
reverse: true,
children: [
SizedBox(height: 30.0),
new Image.asset(
'assets/logo.png',
height: 200.0,
),
titleSection,
textFieldSection,
buttonSection
].reversed.toList(),
),
),
);
}
}
【问题讨论】:
-
我在这里jaycoding.tech/tutorials/guides/… 写了一个基于第三方包的简单解决方案,因为我认为 MediaQuery 还不够。您可能想检查一下。
标签: android mobile dart flutter