zoukankan      html  css  js  c++  java
  • Flutter中的Container和Text组件的常用属性

    效果图:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text("flutter demo"),
            ),
            body: HomeContent(),
          ),
        );
      }
    }
    
    class HomeContent extends StatelessWidget {
      const HomeContent({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Center(
          child: Container(
            child: Text(
              "我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本",
              textAlign: TextAlign.right,
              overflow: TextOverflow.ellipsis,
              maxLines: 10,
              textScaleFactor: 1.5,
              style: TextStyle(
                fontSize: 16.0,
                color: Colors.red,
                fontWeight: FontWeight.w800,
                fontStyle: FontStyle.italic,
                decoration: TextDecoration.lineThrough,
                decorationColor: Colors.white,
                decorationStyle: TextDecorationStyle.dashed,
                wordSpacing: 10.0,
                letterSpacing: 5.0
              ),
            ),
            
            height: 300.0,
            double.infinity,
            decoration: BoxDecoration(
                color: Colors.yellow,
                border: Border.all(
                  color: Colors.blue, 
                   2.0
                  ),
                  borderRadius: BorderRadius.all(
                    Radius.circular(5.0) //圆角:
                  )
                ),
            padding: EdgeInsets.fromLTRB(10, 30, 5, 0),
            margin: EdgeInsets.all(10),
            // transform: Matrix4.translationValues(100, 0, 0),
            // transform: Matrix4.rotationZ(0.3), //
            transform: Matrix4.diagonal3Values(1.2, 1, 0.6),
            alignment: Alignment.bottomLeft,
          ),
        );
      }
    }

     Container设置背景图片:

    Scaffold(
          body: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("images/bg.jpg"),
                fit: BoxFit.cover,
              ),
            ),
            child: Center(
              child: Text('Hello Wolrd', style: TextStyle(fontSize: 22.0, color: Colors.white),),
            ),
          ),
    );
  • 相关阅读:
    Android安卓 _“Activity"_01+简单的拨号器
    Android安卓 “内部类”
    我的第一天 Andorid “hello_world”
    Android sqlite 创建数据库
    Sqlite(代码 jabc)
    判断网络状态
    Android sqlite(jdbc)
    Android 单机事件的使用
    JAVA内部类(成员.局部.匿名)
    我的第一个Android程序
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/11696822.html
Copyright © 2011-2022 走看看