这是我的全部flutter代码,你看下为什么字体没有根据textStyle而改变大小:import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return ScreenUtilInit( designSize: const Size(240, 320), minTextAdapt: true, splitScreenMode: true, builder: (context, child) { return myApp(); }, ); } } class myApp extends StatelessWidget { const myApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'ListView widget', theme: ThemeData( textTheme: TextTheme( bodyLarge: TextStyle(fontSize: 50), )), home: Scaffold( body: Container( color: Colors.white, child: SafeArea( child: Column( children: [ Image.asset( 'lib/images/title.png', width: ScreenUtil().setWidth(240), fit: BoxFit.contain, ), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Image.asset( 'lib/images/aside.png', width: 30, height: ScreenUtil().setWidth(288), fit: BoxFit.cover, alignment: Alignment.topLeft, ), Expanded(flex: 1, child: middleContainer()), Image.asset( 'lib/images/aside.png', width: 30, height: ScreenUtil().setWidth(288), fit: BoxFit.cover, alignment: Alignment.topRight, ), ], ) ], ), ))), ); } } class middleContainer extends StatelessWidget { const middleContainer({super.key}); @override Widget build(BuildContext context) { return Container( height: ScreenUtil().setWidth(288), color: const Color(0xff010042), child: Column(children: [ Expanded( flex: 274, child: Container( color: Colors.amber, )), Expanded( flex: 45, child: Container( color: Color.fromARGB(255, 209, 188, 123), )), Expanded( flex: 60, child: Container( child: Stack( children: [ Positioned( child: Text( '返回', ), bottom: ScreenUtil().setWidth(5), left: ScreenUtil().setWidth(10), ) ], ), color: Color.fromARGB(255, 85, 105, 104), )), ]), ); } }
时间: 2024-01-22 07:19:07 浏览: 191
Flutter入门与实战:屏幕适配和字体大小
5星 · 资源好评率100%
你在 MyApp 的 theme 中定义了一个名为 bodyLarge 的 TextStyle ,但是你没有在代码中指定使用这个 TextStyle。你可以尝试将你的 Text 组件的 style 属性设置为 bodyLarge,例如:
```
Text(
'返回',
style: Theme.of(context).textTheme.bodyLarge,
),
```
这样,你的 Text 组件就会使用你定义的 bodyLarge TextStyle。另外,由于你在 ScreenUtilInit 中设置了 minTextAdapt 为 true,所以你还需要确保你的 Text 组件的 fontSize 没有超过系统最小字号,否则字体大小不会自动适应屏幕。你可以通过在 ScreenUtilInit 中设置 minTextAdapt 值为 false 来关闭最小字号限制。
阅读全文