2

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

我想要这样。我RadioListTileALertDialog. 它会在不同的 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",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 13),
                        ),
                      ],
                    ),
                    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,
                              fontSize: 13,
                              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),

没有什么真正起作用。

我是新来的。请帮忙。先感谢您

4

1 回答 1

1

看看我做的这个例子:

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",
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                  fontSize: 13),
                                            ),
                                          ],
                                        ),
                                        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,
                                                  fontSize: 13,
                                                  decoration: TextDecoration
                                                      .lineThrough),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                    activeColor: Colors.teal,
                                    onChanged: (val) {
                                      setState(() {});
                                    }),
                              ),
                            ),
                            SizedBox(
                              height: 10,
                            ),
                            Container(
                              margin: EdgeInsets.symmetric(horizontal: 10),
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  border: Border.all(
                                      color: Theme.of(context).hintColor,
                                      width: 1.0)),
                              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",
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                  fontSize: 13),
                                            ),
                                          ],
                                        ),
                                        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,
                                                  fontSize: 13,
                                                  decoration: TextDecoration
                                                      .lineThrough),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                    activeColor: Colors.teal,
                                    onChanged: (val) {
                                      setState(() {});
                                    }),
                              ),
                            ),
                            SizedBox(
                              height: 10,
                            ),
                            Container(
                              margin: EdgeInsets.symmetric(horizontal: 10),
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  border: Border.all(
                                      color: Theme.of(context).hintColor,
                                      width: 1.0)),
                              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",
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                  fontSize: 13),
                                            ),
                                          ],
                                        ),
                                        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,
                                                  fontSize: 13,
                                                  decoration: TextDecoration
                                                      .lineThrough),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                    activeColor: Colors.teal,
                                    onChanged: (val) {
                                      setState(() {});
                                    }),
                              ),
                            ),
                            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,
                        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",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 13),
                                    ),
                                  ],
                                ),
                                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,
                                          fontSize: 13,
                                          decoration:
                                              TextDecoration.lineThrough),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                            activeColor: Colors.teal,
                            onChanged: (val) {
                              setState(() {});
                            }),
                      ),
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 10),
                      decoration: BoxDecoration(
                          shape: BoxShape.rectangle,
                          border: Border.all(
                              color: Theme.of(context).hintColor, width: 1.0)),
                      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",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 13),
                                    ),
                                  ],
                                ),
                                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,
                                          fontSize: 13,
                                          decoration:
                                              TextDecoration.lineThrough),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                            activeColor: Colors.teal,
                            onChanged: (val) {
                              setState(() {});
                            }),
                      ),
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 10),
                      decoration: BoxDecoration(
                          shape: BoxShape.rectangle,
                          border: Border.all(
                              color: Theme.of(context).hintColor, width: 1.0)),
                      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",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 13),
                                    ),
                                  ],
                                ),
                                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,
                                          fontSize: 13,
                                          decoration:
                                              TextDecoration.lineThrough),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                            activeColor: Colors.teal,
                            onChanged: (val) {
                              setState(() {});
                            }),
                      ),
                    ),
                    SizedBox(height: 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("your selected value");
                            },
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

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

于 2020-09-12T07:09:35.127 回答