Alert Dialog with Rounded corners in flutter

前端 未结 8 1789
渐次进展
渐次进展 2020-12-23 13:30

I am trying to create an alert dialog with rounded corners in Flutter same as below screenshot. also add my code here, but my output is exactly different from the expected o

8条回答
  •  囚心锁ツ
    2020-12-23 13:35

    Though i am late with the solution, but this may help others searching for it. The following code snippets details how it can be achieved.

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    Color myColor = Color(0xff00bfa5);
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          title: "Rounde Alert Box",
          home: Scaffold(
            appBar: AppBar(
              backgroundColor: myColor,
              title: Text("Rounded Alert Box"),
            ),
            body: RoundedAlertBox(),
          ),
        );
      }
    }
    
    class RoundedAlertBox extends StatefulWidget {
      @override
      _RoundedAlertBoxState createState() => _RoundedAlertBoxState();
    }
    
    class _RoundedAlertBoxState extends State {
      @override
      Widget build(BuildContext context) {
        return Center(
          child: RaisedButton(
            onPressed: openAlertBox,
            color: myColor,
            child: Text(
              "Open Alert Box",
              style: TextStyle(color: Colors.white),
            ),
          ),
        );
      }
    
      openAlertBox() {
        return showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(32.0))),
                contentPadding: EdgeInsets.only(top: 10.0),
                content: Container(
                  width: 300.0,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(
                            "Rate",
                            style: TextStyle(fontSize: 24.0),
                          ),
                          Row(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Icon(
                                Icons.star_border,
                                color: myColor,
                                size: 30.0,
                              ),
                              Icon(
                                Icons.star_border,
                                color: myColor,
                                size: 30.0,
                              ),
                              Icon(
                                Icons.star_border,
                                color: myColor,
                                size: 30.0,
                              ),
                              Icon(
                                Icons.star_border,
                                color: myColor,
                                size: 30.0,
                              ),
                              Icon(
                                Icons.star_border,
                                color: myColor,
                                size: 30.0,
                              ),
                            ],
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 5.0,
                      ),
                      Divider(
                        color: Colors.grey,
                        height: 4.0,
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 30.0, right: 30.0),
                        child: TextField(
                          decoration: InputDecoration(
                            hintText: "Add Review",
                            border: InputBorder.none,
                          ),
                          maxLines: 8,
                        ),
                      ),
                      InkWell(
                        child: Container(
                          padding: EdgeInsets.only(top: 20.0, bottom: 20.0),
                          decoration: BoxDecoration(
                            color: myColor,
                            borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(32.0),
                                bottomRight: Radius.circular(32.0)),
                          ),
                          child: Text(
                            "Rate Product",
                            style: TextStyle(color: Colors.white),
                            textAlign: TextAlign.center,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              );
            });
      }
    }
    

    The output of the code snippet looks like this:

提交回复
热议问题