flutter 绘透明度和自定义widget

Opacity和Color

透明度和字体颜色

child: Text(
        'Hello, How are you? I am fine. Thank you',
        style: TextStyle(color: Colors.red),//红色字体
      ),
child: Text(
        'Hello, How are you? I am fine. Thank you',
        style: TextStyle(color: Colors.red.withOpacity(0.5)),//透明度50%的红色字体
      ),

 

import 'package:flutter/material.dart';

void main() {
  runApp( MaterialApp(
    title: 'Flutter Tutorial',
    home: Counter(),
  ));
}

class Counter extends StatefulWidget {

  @override
  _CounterState createState() => new _CounterState();
}

class _CounterState extends State<Counter> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: CustomButton("Hello"),
    );
  }
}


class CustomButton extends StatelessWidget {
  final String label;

  CustomButton(this.label);

  @override
  Widget build(BuildContext context) {
    return RaisedButton(onPressed: () {}, child: Text(label,style:TextStyle(color: Colors.red.withOpacity(0.5))),);//透明度50%的红色字体));
  }
}

 

posted on 2019-12-16 16:15  高彰  阅读(1657)  评论(0编辑  收藏  举报

导航