feat: 字体大小调节

This commit is contained in:
guozhigq
2023-08-22 20:53:50 +08:00
parent 0fe6d6c8e2
commit 8a8e99f30b
20 changed files with 175 additions and 74 deletions

View File

@ -58,8 +58,11 @@ class VideoCardH extends StatelessWidget {
StyleString.safeSpace, 5, StyleString.safeSpace, 5),
child: LayoutBuilder(
builder: (context, boxConstraints) {
double width =
(boxConstraints.maxWidth - StyleString.cardSpace * 6) / 2;
double width = (boxConstraints.maxWidth -
StyleString.cardSpace *
6 /
MediaQuery.of(context).textScaleFactor) /
2;
return Container(
constraints: const BoxConstraints(minHeight: 88),
height: width / StyleString.aspectRatio,
@ -123,7 +126,7 @@ class VideoContent extends StatelessWidget {
Widget build(BuildContext context) {
return Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 2, 6, 0),
padding: const EdgeInsets.fromLTRB(10, 0, 6, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -132,7 +135,6 @@ class VideoContent extends StatelessWidget {
videoItem.title,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
),
maxLines: 2,
@ -147,7 +149,6 @@ class VideoContent extends StatelessWidget {
TextSpan(
text: i['text'],
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
color: i['type'] == 'em'
@ -177,7 +178,7 @@ class VideoContent extends StatelessWidget {
// color: Theme.of(context).colorScheme.surfaceTint),
// ),
// ),
const SizedBox(height: 4),
// const SizedBox(height: 4),
Row(
children: [
Text(

View File

@ -77,11 +77,8 @@ class VideoCardV extends StatelessWidget {
Widget build(BuildContext context) {
String heroTag = Utils.makeHeroTag(videoItem.id);
return Card(
elevation: 0,
elevation: 1,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: StyleString.mdRadius,
),
margin: EdgeInsets.zero,
child: GestureDetector(
onLongPress: () {
@ -129,14 +126,13 @@ class VideoContent extends StatelessWidget {
Widget build(BuildContext context) {
return Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(4, 8, 0, 3),
padding: const EdgeInsets.fromLTRB(9, 8, 9, 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
videoItem.title,
style: const TextStyle(fontSize: 13),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),

View File

@ -48,6 +48,9 @@ class MyApp extends StatelessWidget {
// 是否动态取色
bool isDynamicColor =
setting.get(SettingBoxKey.dynamicColor, defaultValue: true);
// 字体缩放大小
double textScale =
setting.get(SettingBoxKey.defaultTextScale, defaultValue: 1.0);
return DynamicColorBuilder(
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
@ -107,7 +110,9 @@ class MyApp extends StatelessWidget {
return FlutterSmartDialog(
toastBuilder: (String msg) => CustomToast(msg: msg),
child: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
data: MediaQuery.of(context).copyWith(
textScaleFactor:
MediaQuery.of(context).textScaleFactor * textScale),
child: child!,
),
);

View File

@ -213,7 +213,8 @@ class _BangumiPageState extends State<BangumiPage>
crossAxisSpacing: StyleString.cardSpace,
// 列数
crossAxisCount: 3,
mainAxisExtent: Get.size.width / 3 / 0.65 + 30,
mainAxisExtent: Get.size.width / 3 / 0.65 +
32 * MediaQuery.of(context).textScaleFactor,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {

View File

@ -29,9 +29,6 @@ class BangumiCardV extends StatelessWidget {
return Card(
elevation: 0,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: StyleString.mdRadius,
),
margin: EdgeInsets.zero,
child: GestureDetector(
// onLongPress: () {
@ -149,7 +146,6 @@ class BangumiContent extends StatelessWidget {
bangumiItem.title,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
),
@ -158,6 +154,7 @@ class BangumiContent extends StatelessWidget {
)),
],
),
const SizedBox(height: 1),
if (bangumiItem.indexShow != null)
Text(
bangumiItem.indexShow,

View File

@ -77,7 +77,6 @@ class VideoContent extends StatelessWidget {
favFolderItem.title,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
),

View File

@ -127,32 +127,34 @@ class _FavDetailPageState extends State<FavDetailPage> {
),
),
const SizedBox(width: 14),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
_favDetailController.item!.title!,
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleMedium!
.fontSize,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Text(
_favDetailController.item!.upper!.name!,
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelSmall!
.fontSize,
color: Theme.of(context).colorScheme.outline),
)
],
)
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
_favDetailController.item!.title!,
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleMedium!
.fontSize,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Text(
_favDetailController.item!.upper!.name!,
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelSmall!
.fontSize,
color: Theme.of(context).colorScheme.outline),
)
],
),
),
],
),
),

View File

@ -159,7 +159,6 @@ class VideoContent extends StatelessWidget {
videoItem.title,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
),

View File

@ -205,7 +205,6 @@ class VideoContent extends StatelessWidget {
videoItem.title,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
),

View File

@ -146,7 +146,8 @@ class _LivePageState extends State<LivePage> {
// 列数
crossAxisCount: crossAxisCount,
mainAxisExtent:
Get.size.width / crossAxisCount / StyleString.aspectRatio + 66,
Get.size.width / crossAxisCount / StyleString.aspectRatio +
68 * MediaQuery.of(context).textScaleFactor,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {

View File

@ -23,11 +23,8 @@ class LiveCardV extends StatelessWidget {
Widget build(BuildContext context) {
String heroTag = Utils.makeHeroTag(liveItem.roomId);
return Card(
elevation: 0,
elevation: 1,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: StyleString.mdRadius,
),
margin: EdgeInsets.zero,
child: GestureDetector(
onLongPress: () {
@ -103,7 +100,7 @@ class LiveContent extends StatelessWidget {
return Expanded(
child: Padding(
// 多列
padding: const EdgeInsets.fromLTRB(4, 8, 0, 6),
padding: const EdgeInsets.fromLTRB(9, 9, 9, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -112,7 +109,6 @@ class LiveContent extends StatelessWidget {
liveItem.title,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
),

View File

@ -138,7 +138,7 @@ class _MediaPageState extends State<MediaPage>
// const SizedBox(height: 10),
SizedBox(
width: double.infinity,
height: 170,
height: 170 * MediaQuery.of(context).textScaleFactor,
child: FutureBuilder(
future: _futureBuilderFuture,
builder: (context, snapshot) {

View File

@ -159,7 +159,8 @@ class _RcmdPageState extends State<RcmdPage>
// 列数
crossAxisCount: crossAxisCount,
mainAxisExtent:
Get.size.width / crossAxisCount / StyleString.aspectRatio + 66,
(Get.size.width / crossAxisCount / StyleString.aspectRatio) +
68 * MediaQuery.of(context).textScaleFactor,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {

View File

@ -12,13 +12,12 @@ Widget searchLivePanel(BuildContext context, ctr, list) {
primary: false,
controller: ctr!.scrollController,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: StyleString.cardSpace + 2,
mainAxisSpacing: StyleString.cardSpace + 3,
mainAxisExtent:
MediaQuery.of(context).size.width / 2 / StyleString.aspectRatio +
60,
),
crossAxisCount: 2,
crossAxisSpacing: StyleString.cardSpace + 2,
mainAxisSpacing: StyleString.cardSpace + 3,
mainAxisExtent:
MediaQuery.of(context).size.width / 2 / StyleString.aspectRatio +
66 * MediaQuery.of(context).textScaleFactor),
itemCount: list.length,
itemBuilder: (context, index) {
return LiveItem(liveItem: list![index]);
@ -35,11 +34,8 @@ class LiveItem extends StatelessWidget {
Widget build(BuildContext context) {
String heroTag = Utils.makeHeroTag(liveItem.roomid);
return Card(
elevation: 0,
elevation: 1,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: StyleString.mdRadius,
),
margin: EdgeInsets.zero,
child: InkWell(
onTap: () async {
@ -104,7 +100,7 @@ class LiveContent extends StatelessWidget {
Widget build(BuildContext context) {
return Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(4, 5, 6, 6),
padding: const EdgeInsets.fromLTRB(9, 8, 9, 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -116,7 +112,6 @@ class LiveContent extends StatelessWidget {
TextSpan(
text: i['text'],
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
color: i['type'] == 'em'

View File

@ -68,9 +68,10 @@ Widget searchMbangumiPanel(BuildContext context, ctr, list) {
text: i['text'],
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleSmall!
.fontSize,
.textTheme
.titleSmall!
.fontSize! *
MediaQuery.of(context).textScaleFactor,
fontWeight: FontWeight.bold,
color: i['type'] == 'em'
? Theme.of(context).colorScheme.primary

View File

@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/utils/storage.dart';
class FontSizeSelectPage extends StatefulWidget {
const FontSizeSelectPage({super.key});
@override
State<FontSizeSelectPage> createState() => _FontSizeSelectPageState();
}
class _FontSizeSelectPageState extends State<FontSizeSelectPage> {
Box setting = GStrorage.setting;
List<double> list = [0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3];
late double minsize;
late double maxSize;
late double currentSize;
@override
void initState() {
super.initState();
minsize = list.first;
maxSize = list.last;
currentSize =
setting.get(SettingBoxKey.defaultTextScale, defaultValue: 1.0);
}
setFontSize() {
setting.put(SettingBoxKey.defaultTextScale, currentSize);
Get.forceAppUpdate();
Get.back();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
TextButton(onPressed: () => setFontSize(), child: const Text('确定')),
const SizedBox(width: 12)
],
),
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Center(
child: Text(
'当前字体大小:${currentSize == 1.0 ? '默认' : currentSize}',
style: TextStyle(fontSize: 14 * currentSize),
),
),
),
),
Container(
width: double.infinity,
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: MediaQuery.of(context).padding.bottom + 20,
),
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: Theme.of(context)
.colorScheme
.primary
.withOpacity(0.3))),
color: Theme.of(context).colorScheme.background,
),
child: Row(
children: [
const Text(''),
Expanded(
child: Slider(
min: minsize,
value: currentSize,
max: maxSize,
divisions: list.length - 1,
secondaryTrackValue: 1,
onChanged: (double val) {
currentSize = double.parse(val.toStringAsFixed(2));
setState(() {});
},
),
),
const SizedBox(width: 5),
const Text(
'',
style: TextStyle(fontSize: 20),
),
],
),
)
],
),
);
}
}

View File

@ -189,6 +189,11 @@ class _StyleSettingState extends State<StyleSetting> {
onTap: () => Get.toNamed('/colorSetting'),
title: Text('应用主题', style: titleStyle),
),
ListTile(
dense: false,
onTap: () => Get.toNamed('/fontSizeSetting'),
title: Text('字体大小', style: titleStyle),
)
],
),
);

View File

@ -100,7 +100,7 @@ class IntroDetail extends StatelessWidget {
Text.rich(
style: const TextStyle(
height: 1.4,
fontSize: 13,
// fontSize: 13,
),
TextSpan(
children: [

View File

@ -18,6 +18,7 @@ import 'package:pilipala/pages/search/index.dart';
import 'package:pilipala/pages/searchResult/index.dart';
import 'package:pilipala/pages/setting/extra_setting.dart';
import 'package:pilipala/pages/setting/pages/color_select.dart';
import 'package:pilipala/pages/setting/pages/font_size_select.dart';
import 'package:pilipala/pages/setting/play_setting.dart';
import 'package:pilipala/pages/setting/privacy_setting.dart';
import 'package:pilipala/pages/setting/style_setting.dart';
@ -87,6 +88,7 @@ class Routes {
//
GetPage(name: '/blackListPage', page: () => const BlackListPage()),
GetPage(name: '/colorSetting', page: () => const ColorSelectPage()),
GetPage(name: '/fontSizeSetting', page: () => const FontSizeSelectPage()),
// 关于
GetPage(name: '/about', page: () => const AboutPage()),
];

View File

@ -100,7 +100,7 @@ class SettingBoxKey {
static const String autoUpdate = 'autoUpdate';
static const String themeMode = 'themeMode';
static const String defaultFontSize = 'fontSize';
static const String defaultTextScale = 'textScale';
static const String dynamicColor = 'dynamicColor'; // bool
static const String customColor = 'customColor'; // 自定义主题色
}