不同屏幕尺寸的颤振设计

问题描述 投票:0回答:1

我曾在手机和平​​板电脑上尝试过我的应用。如果另一个屏幕上的设计很好,则设计看起来很糟糕。我共享了手机和平板电脑的图像,因此您可以看到使用不同屏幕尺寸的设计看起来有所不同。如何通过Flutter如何在所有不同屏幕尺寸上设置我的设计?

我的代码:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(Myapp());
}

class Myapp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.red),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text(
            "The Bar ",
            style: TextStyle(
              color: Colors.white,
              fontSize: 28.0,
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          splashColor: Colors.green,
          child: Icon(
            Icons.mouse,
            color: Colors.white,
          ),
          onPressed: () {
            print("You was clicked the button!");
          },
        ),
        body: Column(
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            Text(
              "Kinds of Butoons and Images",
              style: TextStyle(fontSize: 26, color: Colors.blue),
              textAlign: TextAlign.center,
            ),
            Container(
              child: Expanded(
                flex: 1,
                child:Column(
                  children: <Widget>[
                    Container(
                      child: Row(
                        children: <Widget>[
                          Expanded(

                            child: Container(
                              margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
                              child: Row(
                                children: <Widget>[
                                  Container(
                                    child: Expanded(
                                      flex: 1,
                                      child: Container(
                                        margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
                                        child: Column(
                                          children: <Widget>[
                                            CircleAvatar(
                                              backgroundImage: AssetImage("assets/images/test.jpg"),
                                              radius: 140,

                                            ),
                                            Text(
                                              "X",
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    child: Expanded(
                                      flex: 1,
                                      child: Container(
                                        margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
                                        child: Column(
                                          children: <Widget>[
                                            Image(
                                              image: AssetImage(
                                                  "assets/images/test.jpg"),
                                            ),
                                            Text(
                                              "X",
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    child: Expanded(
                                      flex: 1,
                                      child: Container(
                                        margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
                                        child: Column(
                                          children: <Widget>[
                                            Image(
                                              image: AssetImage(
                                                  "assets/images/test.jpg"),
                                            ),
                                            Text(
                                              "X",
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),

                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              child: Expanded(
                flex: 1,
                child:Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Container(
                      child: Row(
                        children: <Widget>[
                          Expanded(

                            child: Container(
                              margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
                              child: Row(
                                children: <Widget>[
                                  Container(
                                    child: Expanded(
                                      flex: 1,
                                      child: Container(
                                        margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
                                        child: Column(
                                          children: <Widget>[
                                            CircleAvatar(
                                              backgroundImage: AssetImage("assets/images/test.jpg"),
                                              radius: 140,

                                            ),
                                            Text(
                                              "X",
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    child: Expanded(
                                      flex: 1,
                                      child: Container(
                                        margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
                                        child: Column(
                                          children: <Widget>[
                                            Image(
                                              image: AssetImage(
                                                  "assets/images/test.jpg"),
                                            ),
                                            Text(
                                              "X",
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    child: Expanded(
                                      flex: 1,
                                      child: Container(
                                        margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
                                        child: Column(
                                          children: <Widget>[
                                            Image(
                                              image: AssetImage(
                                                  "assets/images/test.jpg"),
                                            ),
                                            Text(
                                              "X",
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),

                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

it is my sample results(one is phone the other is a tablet)

flutter flutter-layout flutter-container
1个回答
0
投票

要限制CircleAvatar的高度,请使用LayoutBuilderConstrainedBox

LayoutBuilder(
  builder: (context, constraints) {
    return ConstrainedBox(
      constraints: BoxConstraints(
        maxHeight: constraints.maxWidth, 
        maxWidth: constraints.maxWidth
      ),
      child: CircleAvatar(
        backgroundImage: NetworkImage('...'),
        radius: 140,
      ),
    );
  }
),

1

© www.soinside.com 2019 - 2024. All rights reserved.