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)
);
}
}
网友评论