LiZhuoyuan

尝试添加个预设字体

1 import 'dart:ui'; 1 import 'dart:ui';
2 2
  3 +import 'package:example/text_style.dart';
3 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
4 import 'package:flutter_screenutil/flutter_screenutil.dart'; 5 import 'package:flutter_screenutil/flutter_screenutil.dart';
5 6
@@ -107,10 +108,7 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -107,10 +108,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
107 )), 108 )),
108 Text( 109 Text(
109 'My font size is 24px on the design draft and will change with the system.', 110 'My font size is 24px on the design draft and will change with the system.',
110 - style: TextStyle(  
111 - color: Colors.black,  
112 - fontSize: ScreenUtil()  
113 - .setSp(24, allowFontScalingSelf: true))), 111 + style: ts.t1),
114 ], 112 ],
115 ) 113 )
116 ], 114 ],
  1 +import 'package:example/text_style.dart';
1 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
2 import 'package:flutter_screenutil/flutter_screenutil.dart'; 3 import 'package:flutter_screenutil/flutter_screenutil.dart';
3 4
@@ -31,7 +32,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -31,7 +32,7 @@ class _MyHomePageState extends State<MyHomePage> {
31 Widget build(BuildContext context) { 32 Widget build(BuildContext context) {
32 //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334) 33 //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
33 34
34 - ScreenUtil.init(context,width: 750, height: 1334, allowFontScaling: false); 35 + ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
35 36
36 return ExampleWidget(title: 'FlutterScreenUtil示例'); 37 return ExampleWidget(title: 'FlutterScreenUtil示例');
37 } 38 }
@@ -108,16 +109,14 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -108,16 +109,14 @@ class _ExampleWidgetState extends State<ExampleWidget> {
108 Column( 109 Column(
109 crossAxisAlignment: CrossAxisAlignment.start, 110 crossAxisAlignment: CrossAxisAlignment.start,
110 children: <Widget>[ 111 children: <Widget>[
111 - Text('我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',  
112 - style: TextStyle(  
113 - color: Colors.black,  
114 - fontSize: 24.sp,  
115 - )),  
116 - Text('我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',  
117 - style: TextStyle(  
118 - color: Colors.black,  
119 - fontSize: ScreenUtil()  
120 - .setSp(24, allowFontScalingSelf: true))), 112 + Text(
  113 + '我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化',
  114 + style: ts.t2,
  115 + ),
  116 + Text(
  117 + '我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化',
  118 + style: ts.t1,
  119 + ),
121 ], 120 ],
122 ) 121 )
123 ], 122 ],
@@ -126,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> { @@ -126,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
126 floatingActionButton: FloatingActionButton( 125 floatingActionButton: FloatingActionButton(
127 child: Icon(Icons.title), 126 child: Icon(Icons.title),
128 onPressed: () { 127 onPressed: () {
129 - ScreenUtil.init(context,width: 1500, height: 1334, allowFontScaling: false); 128 + ScreenUtil.init(context,
  129 + width: 1500, height: 1334, allowFontScaling: false);
130 setState(() {}); 130 setState(() {});
131 }, 131 },
132 ), 132 ),
  1 +import 'package:flutter/material.dart';
  2 +import 'package:flutter_screenutil/flutter_screenutil.dart';
  3 +
  4 +class TextStyles {
  5 + TextStyle t1 = TextStyle(fontSize: 24.ssp, color: Colors.black);
  6 + TextStyle t2 = TextStyle(fontSize: 24.sp, color: Colors.black);
  7 +}
  8 +
  9 +var ts = TextStyles();
  10 +
  11 +class TextStyle2 {
  12 + static TextStyle2 ts2;
  13 +
  14 + factory TextStyle2() {
  15 + if (ts2 == null) {
  16 + ts2 = TextStyle2();
  17 + }
  18 + return ts2;
  19 + }
  20 +
  21 + TextStyle t1 = TextStyle(fontSize: 24.ssp, color: Colors.black);
  22 + TextStyle t2 = TextStyle(fontSize: 24.sp, color: Colors.black);
  23 +}