Flutter布局之图片圆角画廊

作者: TryEnough | 来源:发表于2019-01-06 23:30 被阅读1次

    教程推荐


    效果图

    TryEnough

    代码

    
    import 'package:flutter/material.dart';
    // Uncomment lines 7 and 10 to view the visual layout at runtime.
    import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
    
    void main() {
      debugPaintSizeEnabled = true; //分析 1
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        var container = Container(
          decoration: BoxDecoration(
            color: Colors.black26,
          ),
          child: Column(  //分析 2
            children: [
              Row(
                children: [
                  Expanded(
                    child: Container(
                      decoration: BoxDecoration(  // 分析 3
                        border: Border.all(width: 5.0, color: Colors.black),
                        borderRadius:
                        const BorderRadius.all(const Radius.circular(8.0)),
                      ),
                      margin: const EdgeInsets.all(4.0),
                      child: Image.asset('images/timg.jpeg'),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      decoration: BoxDecoration(
                        border: Border.all(width: 10.0, color: Colors.black38),
                        borderRadius:
                        const BorderRadius.all(const Radius.circular(0.0)),
                      ),
                      margin: const EdgeInsets.all(4.0),
                      child: Image.asset('images/timg.jpeg'),
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Expanded(
                    child: Container(
                      decoration: BoxDecoration(
                        border: Border.all(width: 10.0, color: Colors.red),
                        borderRadius:
                        const BorderRadius.all(const Radius.circular(8.0)),
                      ),
                      margin: const EdgeInsets.all(4.0),
                      child: Image.asset('images/timg.jpeg'),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      decoration: BoxDecoration(
                        border: Border.all(width: 10.0, color: Colors.black38),
                        borderRadius:
                        const BorderRadius.all(const Radius.circular(8.0)),
                      ),
                      margin: const EdgeInsets.all(16.0),
                      child: Image.asset('images/timg.jpeg'),
                    ),
                  ),
                ],
              ),
            ],
          ),
        );
    
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: container,
          ),
        );
      }
    }
    

    分析

    • 分析1:
      开启调试模式

    • 分析2
      四张图片放在一个column的children中,分为两行,每行再添加两个container

    • 分析3
      添加边框,设置边框的颜色和宽度

    相关文章

      网友评论

        本文标题:Flutter布局之图片圆角画廊

        本文链接:https://www.haomeiwen.com/subject/xxaerqtx.html