4.Flutter封装Text

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home:Scaffold(
        appBar: AppBar(title:Text('文本控件的使用'),),
        body:HomeContent())
    );
  }
}

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: ZText('我的文本', Colors.red, 20, 1)
    );
  }
}

class ZText extends StatelessWidget {

  final String str;
  final Color color;
  final double fontSize;
  final double fontWeight;

  ZText(this.str, this.color, this.fontSize, this.fontWeight);

  @override
  Widget build(BuildContext context) {
    return Text(str,
      style: TextStyle(
        color: color,
        fontSize: fontSize,
        fontWeight: fontWeight == 1 ? FontWeight.w400 : FontWeight.w600)
    );
  }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容