不同分辨率设备上的Flutter AlertDialog小部件大小问题

问题描述

https://i.stack.imgur.com/oUxNk.jpg

我想要这样。我在RadioListTile中使用过ALertDialog。这会导致在不同的android设备中出现大小不同的对话框。因此导致像素错误溢出或只是黑屏。

这是我的代码

@override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size;

return AlertDialog(
        insetPadding: EdgeInsets.symmetric(
            horizontal: SizeConfig.safeBlockHorizontal * 16,vertical: SizeConfig.safeBlockHorizontal * 40),title: Text("Methods"),content: ListView(children: <Widget>[
          Container(
            decoration: Boxdecoration(
                shape: BoxShape.rectangle,border: Border.all(
                    color: Theme.of(context).hintColor,width: 1.0)),child: RadioListTile(
                value: 1,groupValue: _crtIndex,title: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
                        Text(
                          "12 months",style: TextStyle(
                              fontWeight: FontWeight.bold,fontSize: 13),),Text(
                          "Rs.4,375",],SizedBox(width: size.width * 0.005),Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
                        Text(
                          "50% off",style: TextStyle(
                            fontWeight: FontWeight.normal,fontSize: 13,Text(
                          "9,876",style: TextStyle(
                              fontWeight: FontWeight.normal,decoration: Textdecoration.lineThrough),activeColor: Colors.teal,onChanged: (val) {
                  setState(() {
                    _crtIndex = val;
                  });
                }),SizedBox(height: size.height * 0.01),new FlatButton(
        color: Colors.red,child: new Text('BUY Now AND SAVE'),onpressed: () {
           Navigator.of(context).pop();
        },]));

我还尝试将AlertDialog放在SizedBox内以及Container内,并尝试设置高度和宽度。

我已经使用Size size = MediaQuery.of(context).size;获取高度和宽度。

我也尝试过insetPadding: EdgeInsets.symmetric(horizontal: *value,vertical: *value),

什么都没有。

我是新手。请帮忙。预先谢谢你

解决方法

看看我做的这个例子:

import 'package:flutter/material.dart';

import 'package:json_parsing_example/offerScreen.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Login(),debugShowCheckedModeBanner: false,);
  }
}

class Login extends StatefulWidget {
  @override
  _LoginState createState() => _LoginState();
}

class _LoginState extends State<Login> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SafeArea(
            child: Center(
      child: Column(
        children: <Widget>[
          RaisedButton(
            child: Text('Tap'),onPressed: () async {
              var response = await Navigator.push(
                  context,MaterialPageRoute(
                    builder: (context) => OfferPage(),));
              if (response !=
                  null) // This is when the user presses the back button
              {
                // if user inputs anything then this is where the output will come
                print(response);
              }

              //this response is you value that you selected
              // you can do processing on this page or the selection
              //page
            },),RaisedButton(
            child: Text('Tap2'),onPressed: () {
              showModalBottomSheet(
                isScrollControlled: true,context: context,shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(20),clipBehavior: Clip.antiAliasWithSaveLayer,builder: (context) => Container(
                  height: MediaQuery.of(context).size.height * 0.95,child: Column(
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.only(right: 12,top: 15),child: GestureDetector(
                              onTap: () {
                                Navigator.of(context).pop(null);
                              },child: Icon(
                                Icons.close,size: 30,],Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
                            Container(
                              margin: EdgeInsets.symmetric(horizontal: 10),decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,border: Border.all(
                                      color: Theme.of(context).hintColor,width: 0.5)),child: Padding(
                                padding: const EdgeInsets.all(8.0),child: RadioListTile(
                                    value: 1,groupValue: 1,title: Column(
                                      children: [
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,children: [
                                            Text(
                                              "12 months",style: TextStyle(
                                                  fontWeight: FontWeight.bold,fontSize: 13),Text(
                                              "Rs.4,375",SizedBox(
                                            width: MediaQuery.of(context)
                                                    .size
                                                    .width *
                                                0.005),Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,children: [
                                            Text(
                                              "50% off",style: TextStyle(
                                                fontWeight: FontWeight.normal,fontSize: 13,Text(
                                              "9,876",style: TextStyle(
                                                  fontWeight: FontWeight.normal,decoration: TextDecoration
                                                      .lineThrough),activeColor: Colors.teal,onChanged: (val) {
                                      setState(() {});
                                    }),SizedBox(
                              height: 10,Container(
                              margin: EdgeInsets.symmetric(horizontal: 10),width: 1.0)),SizedBox(
                                height:
                                    MediaQuery.of(context).size.height * 0.01),Container(
                              width: MediaQuery.of(context).size.width,height: 60,child: Expanded(
                                child: Padding(
                                  padding: const EdgeInsets.symmetric(
                                      horizontal: 10),child: new FlatButton(
                                    color: Colors.red,child: new Text(
                                      'BUY NOW AND SAVE',style: TextStyle(
                                        color: Colors.white,onPressed: () {
                                      Navigator.of(context).pop();
                                    },);
            },)));
  }
}

这是要约页面:

import 'package:flutter/material.dart';

class OfferPage extends StatefulWidget {
  @override
  _OfferPageState createState() => _OfferPageState();
}

class _OfferPageState extends State<OfferPage> {
  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: Colors.white,body: SafeArea(
        child: Container(
          height: MediaQuery.of(context).size.height,width: MediaQuery.of(context).size.width,child: Column(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.end,children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.all(8.0),child: GestureDetector(
                      onTap: () {
                        Navigator.of(context).pop(null);
                      },child: Icon(
                        Icons.close,Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 10),decoration: BoxDecoration(
                          shape: BoxShape.rectangle,border: Border.all(
                              color: Theme.of(context).hintColor,child: Padding(
                        padding: const EdgeInsets.all(8.0),child: RadioListTile(
                            value: 1,title: Column(
                              children: [
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,children: [
                                    Text(
                                      "12 months",style: TextStyle(
                                          fontWeight: FontWeight.bold,Text(
                                      "Rs.4,SizedBox(width: size.width * 0.005),Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,children: [
                                    Text(
                                      "50% off",style: TextStyle(
                                        fontWeight: FontWeight.normal,Text(
                                      "9,style: TextStyle(
                                          fontWeight: FontWeight.normal,decoration:
                                              TextDecoration.lineThrough),onChanged: (val) {
                              setState(() {});
                            }),SizedBox(
                      height: 10,Container(
                      margin: EdgeInsets.symmetric(horizontal: 10),SizedBox(height: size.height * 0.01),Container(
                      width: MediaQuery.of(context).size.width,child: Expanded(
                        child: Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 10),child: new FlatButton(
                            color: Colors.red,child: new Text(
                              'BUY NOW AND SAVE',style: TextStyle(
                                color: Colors.white,onPressed: () {
                              Navigator.of(context).pop("your selected value");
                            },);
  }
}

检查一下,让我知道它是否有效。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...