import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; void main(){ //开启调试线条,比如引入rendering.dart debugPaintSizeEnabled = true; runApp(MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key key}) : super(key: key); @override Widget build(BuildContext context) { //DefaultTextStyle用法1: var text1 = DefaultTextStyle.merge( style: TextStyle( color: Colors.red, fontWeight: FontWeight.w800, fontFamily: 'Roboto', fontSize: 12.0, height: 1.2 //行高,倍数 ), child: Row( children: [ Column( children: [ Text('PREP'), Text('25 min') ], ), Column( children: [ Text('COOK'), Text('1 hours', style: TextStyle(color: Colors.blue),) ], ), Column( children: [ Text('PEEDS'), Text('4-6') ], ) ], ), ); var text2 = Container( width: 150, color: Colors.red, child: DefaultTextStyle( style: TextStyle(fontSize: 18), // TextOverflow.clip:直接截取 // TextOverflow.fade:渐隐 // TextOverflow.ellipsis:省略号形式 // TextOverflow.visible:可见 overflow: TextOverflow.ellipsis, child: Text('我爱模板网,我爱模板网,我爱模板网,我爱模板网,我爱模板网,'), ), ); return MaterialApp( title: 'DefaultTextStyle', theme: ThemeData( primarySwatch: Colors.blue ), debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: Text('DefaultTextStyle'), ), body: Column( children: [ text1, text2 ], ) ), ); } }
部分素材资源来源网站,本站提供免费下载,如有侵权请联系站长马上删除!