From 1cd30c296ded07d184132924faf0a31cd4b6b4f9 Mon Sep 17 00:00:00 2001 From: debuggerx Date: Fri, 21 Apr 2023 16:45:22 +0800 Subject: [PATCH] feat: screen adaptation; set font family to 'Noto Sans CJK SC' --- lib/main.dart | 91 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8ab0a74..3916bbb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -59,6 +59,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, + fontFamily: 'Noto Sans CJK SC', ), home: const MyHomePage(), ); @@ -144,9 +145,13 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { - if (MediaQuery.of(context).size.shortestSide < 10) { + var shortestSide = MediaQuery.of(context).size.shortestSide; + if (shortestSide < 10) { return const SizedBox.shrink(); } + + var scale = shortestSide / 2000; + return GestureDetector( onTap: () { if ([ @@ -170,11 +175,11 @@ class _MyHomePageState extends State { Center( child: Container( decoration: BoxDecoration( - borderRadius: BorderRadius.circular(24), + borderRadius: BorderRadius.circular(24 * scale), color: Colors.grey.shade700.withOpacity(0.9), ), - width: 460, - height: 360, + width: 460 * scale, + height: 360 * scale, child: Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -187,8 +192,8 @@ class _MyHomePageState extends State { Status.found: 'assets/ok.gif', Status.notFound: 'assets/no.gif', }[status]!, - width: 200, - height: 200, + width: 200 * scale, + height: 200 * scale, fit: BoxFit.fitHeight, ), ), @@ -198,9 +203,9 @@ class _MyHomePageState extends State { Status.found: '小浣熊成功找到${codes.length}个二维码!', Status.notFound: '小浣熊找了一圈,啥也没发现……', }[status]!, - style: const TextStyle( + style: TextStyle( color: Colors.white, - fontSize: 28, + fontSize: 28 * scale, ), ), ], @@ -212,7 +217,7 @@ class _MyHomePageState extends State { (code) { var centerAndSize = getCenterAndSizeOfPoints(code.points); var center = centerAndSize.center - currentWindowPos; - var size = max(centerAndSize.size, 300); + var size = max(centerAndSize.size, 300) * scale; return Positioned( left: center.dx - size / 2, top: center.dy - size / 2, @@ -229,10 +234,10 @@ class _MyHomePageState extends State { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, children: [ - const Text( + Text( '二维码内容:', style: TextStyle( - fontSize: 28, + fontSize: 28 * scale, color: Colors.white, fontWeight: FontWeight.w600, ), @@ -240,11 +245,11 @@ class _MyHomePageState extends State { Flexible( child: AutoSizeText( code.content.split('').join('\u{200B}'), - style: const TextStyle( - fontSize: 28, + style: TextStyle( + fontSize: 28 * scale, color: Colors.white, ), - minFontSize: 16, + minFontSize: 1, maxFontSize: 46, ), ), @@ -252,34 +257,42 @@ class _MyHomePageState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - FilledButton( - onPressed: () { - Clipboard.setData( - ClipboardData(text: code.content), - ).then((_) { - Future.delayed(const Duration(milliseconds: 300), () { - exit(0); - }); - }); - }, - child: const Text( - '复制', - style: TextStyle(fontSize: 28), + Flexible( + child: FittedBox( + child: FilledButton( + onPressed: () { + Clipboard.setData( + ClipboardData(text: code.content), + ).then((_) { + Future.delayed(const Duration(milliseconds: 300), () { + exit(0); + }); + }); + }, + child: Text( + '复制', + style: TextStyle(fontSize: 28 * scale), + ), + ), ), ), SizedBox(width: size / 20), - FilledButton( - onPressed: () async { - var url = code.content; - if (await canLaunchUrlString(url)) { - launchUrlString(url).then((value) { - exit(0); - }); - } - }, - child: const Text( - '打开', - style: TextStyle(fontSize: 28), + Flexible( + child: FittedBox( + child: FilledButton( + onPressed: () async { + var url = code.content; + if (await canLaunchUrlString(url)) { + launchUrlString(url).then((value) { + exit(0); + }); + } + }, + child: Text( + '打开', + style: TextStyle(fontSize: 28 * scale), + ), + ), ), ), ],