代码之家  ›  专栏  ›  技术社区  ›  Farhana Naaz Ansari Jay Dwivedi

颤振响应用户界面

  •  -2
  • Farhana Naaz Ansari Jay Dwivedi  · 技术社区  · 7 年前

    在Ui页边距中,填充、文本和图像大小都是常量。我没用 Fractional box 和 Constraint box media query

    我像这样使用了媒体查询,但无法正确设置。

        double width = MediaQuery.of(context).size.width;
        double height = MediaQuery.of(context).size.height;
        double height35 = height * 0.35;
    

    padding:const EdgeInsets.only(left: 25.0,right: 25.0) ,如何从媒体查询设置填充和其他固定大小。 Here 1 Here 2 是文档和示例,但未从媒体查询中找到。。

    library 我也是,但它没有我想要的那么有效。

    class _LoginPageState extends State<LoginPage> {
      @override
      Widget build(BuildContext context) {
        MediaQueryData queryData;
        queryData = MediaQuery.of(context);
    
    
        double width = MediaQuery.of(context).size.width;
        double height = MediaQuery.of(context).size.height;
        double height35 = height * 0.35;
    
        return Scaffold(
          body: Container(
              decoration: BoxDecoration(color: Color(0xFFE7F6FD)),
            child: Column(
              children: <Widget>[
                SizedBox(height: height35,),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      height: 50.0,
                      child: IconButton(icon: Icon(Icons.close,color: Color(0xFF005283),size: 36.0,), onPressed: null),
                    ),
                  ],),
                Container(child: SingleChildScrollView(
                  padding:const EdgeInsets.only(left: 25.0,right: 25.0),
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      Container(
                        height: 60.0,
                        child: Image.asset('assets/images/login_logo.png')),
    
                      SizedBox(
                        height: 30.0,
                      ),
                      TextFormField(
                        style: new TextStyle(fontSize:18.0,color: Color(0xFF005283)),
                        decoration: InputDecoration(
                          // prefixIcon: Icon(Icons.email, color: Colors.grey),
                            enabledBorder: UnderlineInputBorder(borderSide: new BorderSide(color: Color(0xFF005283))),
                            hintStyle: TextStyle(color: Color(0xFF005283),fontSize:18.0,fontFamily: "WorkSansLight"),
                            hintText: 'Email/Mobile No.'),
                      ),
                      SizedBox(
                        height: 30.0,
                      ),
                      TextFormField(
                        style: new TextStyle(fontSize:18.0,color: Color(0xFF005283)),
                        obscureText: true,
                        decoration: InputDecoration(
                          // prefixIcon: Icon(Icons.email, color: Colors.grey),
                            labelStyle: new TextStyle(color: Colors.blue),
                            enabledBorder: UnderlineInputBorder(borderSide: new BorderSide(color: Color(0xFF005283))),
                            hintStyle: TextStyle(color: Color(0xFF005283),fontSize:18.0,fontFamily: "WorkSansLight"),
                            hintText: 'Password'),
                      ),
                      SizedBox(
                        height: 30.0,
                      ),
    
                      RaisedButton(
                        onPressed: () {
    
                        },
                        shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)),
                        child: Padding(
                            padding: EdgeInsets.only(top:18.0,bottom: 18.0,left: 10.0,right: 10.0),
                            child: Text('LOG IN',style: new TextStyle(fontSize:18.0,color: Color(0xFF005283),fontFamily: "WorkSansMedium"),)),
                        color: Color(0xFFc1ff02),
                        textColor: Colors.white,),
    
                      SizedBox(
                        height: 30.0,),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Divider(
                              color: Color(0xFF005283),
                              height: 8.0,
                            ),
                          ),
                          SizedBox(
                            width: 8.0,
                          ),
                          Text(
                            'OR CONNECT WITH',
                            style: TextStyle(fontSize:14.0,color: Color(0xFF005283),fontFamily: "WorkSansLight",fontWeight: FontWeight.normal),
                          ),
                         SizedBox(
                              width: 8.0,
                          ),
                          Expanded(
                            child: Divider(
                              color: Color(0xFF005283),
                              height: 8.0,
                            ),
                          )
                        ],
                      ),
    
                      Row(
                        children: <Widget>[
                          FlatButton.icon(
                              onPressed: null,
                              label: Text('Login with Facebook',style: TextStyle(color: Colors.white),),
                              icon: Icon(Icons.local_gas_station,color: Colors.white,),
                              shape: Border.all(color: Colors.grey,width: 2.0,style: BorderStyle.none ),
                              //shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0),)
                          ),
    
                          OutlineButton(
                            color: Colors.black,
                              child: new Text("Button text"),
                              onPressed: null,
                              shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                  Center(
                    child: GestureDetector(
                      onTap: () {
                        Navigator.pushNamed(context, "myRoute");
                      },
                      child:  RichText(
                        text: new TextSpan(
                          children: <TextSpan>[
                            TextSpan(text:'Not a Member? ',style: TextStyle(color: Color(0xFF005283),fontSize: 14.0,fontWeight: FontWeight.w400),),
                            TextSpan(text:'Register Now',style: TextStyle(color: Color(0xFF005283),fontSize: 18.0,fontWeight: FontWeight.w600),),
                          ],
                        ),
                      ),
                    ) ,
                  ),
                      SizedBox(
                        height: 20.0,
                      ),
    
                      OutlineButton(
                          color: Color(0xFF005283),
                          child: new Text("CONTINUE AS GUEST",style: TextStyle(color: Color(0xFF005283),fontSize: 14.0,)),
                          onPressed: null,
                          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
                      ),
                ],),))
              ],
            ),
          ),
        );
      }
    }
    

    enter image description here

    2 回复  |  直到 7 年前
        1
  •  0
  •   dshukertjr    7 年前

    从devicePixelRatio属性的文档中: https://docs.flutter.io/flutter/dart-ui/Window/devicePixelRatio.html

    不是二的幂。事实上,它甚至可能不是一个整数。对于

    设备像素也称为物理像素。逻辑像素 也被称为设备独立或分辨率独立 像素。

    根据定义,每厘米大约有38个逻辑像素,或者 物理显示器的每英寸约96个逻辑像素。价值 devicePixelRatio返回的值最终从 硬件本身、设备驱动程序或存储在 巨大的差距。

    颤振框架以逻辑像素运行,因此很少使用 必须直接处理该财产。

    因此,您实际上不必担心设备分辨率,但如果您想访问该属性,您可以如下所示:

    double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;