美文网首页
4.Flutter封装Text

4.Flutter封装Text

作者: 李响2022 | 来源:发表于2020-03-03 00:54 被阅读0次
    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)
        );
      }
    }
    

    相关文章

      网友评论

          本文标题:4.Flutter封装Text

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