将对象放置在容器内

时间:2019-03-15 10:03:54

标签: flutter flutter-layout

新手扑扑的问题。

因此,我正在寻找将小部件放置在容器内的最有效方法;我之所以这样问,是因为我发现像栈这样的小部件非常难接线,并将其定位到像素上。我想了解尝试定位此小部件的更好方法。

此方法在statefulWidget内部被调用。

 Widget myContainer() {
    double c_width = MediaQuery.of(context).size.width * 0.7;

    var logo = Icon(
      Icons.local_florist,
      color: Colors.lightBlue,
      size: 40.0,
    );
    var pitchLine1 = Text(
      'Starter line',
      style: TextStyle(fontSize: 40.0),
      textAlign: TextAlign.left,
    );

    var pitchLine2 = Text(
      'Starter line 2',
      style: TextStyle(fontSize: 40.0),
      textAlign: TextAlign.left,
    );

    var valueProp = Text(
      'All Stars. Increase your sales and understand your customers better with Great Reviews.',
      style: TextStyle(fontSize: 20.0),
      textAlign: TextAlign.left,
    );

    var conditionsApply = Text(
      'By continuing, you agree to ReviewPro\'s Terms of Use and Privacy Policy',
      style: TextStyle(fontSize: 15.0),
      textAlign: TextAlign.center,
    );

    return SafeArea(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Expanded(
            flex: 5,
            child: Container(
              color: Colors.white,
              padding: const EdgeInsets.only(
                  left: 35.0, top: 25.0, right: 35.0, bottom: 35.0),
              child: Stack(
                children: <Widget>[
                  Positioned(
                    top: 10,
                    left: 5,
                    child: logo,
                  ),
                  Positioned(
                    top: 50,
                    left: 5,
                    height: 40,
                    width: c_width,
                    child: pitchLine1,
                  ),
                  Positioned(
                    top: 90,
                    left: 5,
                    height: 40,
                    width: c_width,
                    child: pitchLine2,
                  ),
                  Positioned(
                    top: 150,
                    left: 5,
                    height: 20,
                    width: c_width,
                    child: valueProp,
                  ),
                ],
              ),
            ),
          ),
          Expanded(
            flex: 5,
            child: Container(
              padding: const EdgeInsets.only(
                  left: 35.0, top: 20.0, right: 35.0, bottom: 10.0),
              child: Stack(
                children: <Widget>[
                  Positioned(
                    top: 20,
                    left: 5,
                    width: 300,
//                    height: 20,
                    child: TextField(
                      decoration: InputDecoration(
                          hintText: 'Login with Google Credentials',
                          filled: true,
                          fillColor: Colors.white),
                      autofocus: true,
                    ),
                  ),
                  Positioned(
                    top: 150,
                    left: 5,
                    width: 300,
//                    height:30,
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(40),
                      child: RaisedButton(
                        child: Text("Sign up "),
                        onPressed: () {
                          Navigator.push(
                            context,
                            new MaterialPageRoute(
                                builder: (context) => new ReviewProSkeleton()),
                          );

                        },
                      ),
                    ),
                  ),
                  Positioned(
                    top: 250,
                    left: 5,
                    width: c_width,
//                    height: 20,
                    child: conditionsApply,
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );

}

This is what is being populated by the above widget

1 个答案:

答案 0 :(得分:0)

这就是我所做的:

# class definition for an n-sided die

# import packages

import random

class MSdie(object): 
  #constructor here

    def __init__( self ):
        self.sides = 6
        self.roll()

#define classmethod 'roll' to roll the MSdie

    def roll( self ):

        self.value = 1 + random.randrange(self.sides)

        return self.value

#define classmethod 'getValue' to return the current value of the MSdie

    def getValue(  self ):

        return self.value

#define classmethod 'setValue' to set the die to a particular value
    #def setValue(self):

def roller():
    r1 = MSdie()

    for n in range (4):
        print(r1.roll())

roller()

这是我进行更改后的屏幕外观:

Much neater and not as hard wired as in the beginning