简体   繁体   English

Flutter Web - iOS 上的奇怪缩放

[英]Flutter Web - Weird scaling on iOS

So I'm messing around with Flutter for the web and threw together a little (XKCD-style) password generator just for an experimentation project.所以我为 web 搞乱了 Flutter 并为一个实验项目拼凑了一个小(XKCD 风格)密码生成器。

(Yes, I know Flutter isn't suited for web sites, more for web apps, I'm just trying to get handle on how it works on the web.) (Yes, I know Flutter isn't suited for web sites, more for web apps, I'm just trying to get handle on how it works on the web.)

So you can check it out here: https://pass.lumberstack.org所以你可以在这里查看: https://pass.lumberstack.org

On desktop, it looks like this:在桌面上,它看起来像这样:

Mac 屏幕截图 - 适用于桌面

On Android, it looks like this:在 Android 上,它看起来像这样:

Android 屏幕截图 - 适用于移动设备

On iOS, it looks like this:在 iOS 上,它看起来像这样:

iOS 屏幕截图 - 文本缩放太小

Yes, that's the image and text scaled super small for some reason.是的,由于某种原因,图像和文本的缩放比例非常小。 If I force it to request the desktop site it works as Android does.如果我强迫它请求桌面站点,它就像 Android 一样工作。 Any idea what I'm doing wrong?知道我做错了什么吗?

I tried forcing it to only use canvas kit using flutter build web --web-renderer canvaskit but it behaves the same.我尝试使用flutter build web --web-renderer canvaskit强制它仅使用 canvas 套件,但它的行为相同。

main.dart below. main.dart 下面。

import 'package:flutter/material.dart';
import 'package:password_tool/constants.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:flutter/services.dart';
import 'dart:math';

import 'package:password_tool/cross_fade.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Lumberstack PassGen',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Password Generator'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String password = '';
  String list = '';

  void _generate() {
    setState(() {
      var gen = Random.secure();
      List<String> pickedWords = List<String>.generate(
          4, (_) => kWordList[gen.nextInt(kWordList.length)]);
      password = pickedWords.join("-");
    });
  }

  void _copy() {
    Clipboard.setData(new ClipboardData(text: password));
  }

  @override
  Widget build(BuildContext context) {
    _generate();
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            stops: [0.7, 0.7],
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
            colors: [kAppSecondaryColor, kAppPrimaryColor],
          ),
        ),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Spacer(
                flex: 1,
              ),
              SvgPicture.asset(
                'assets/svgs/logo.svg',
                semanticsLabel: 'Acme Logo',
                width: 75,
                height: 75,
              ),
              Padding(
                padding: const EdgeInsets.only(top: 30),
                child: Text(
                  'Password Generator',
                  style: GoogleFonts.montserrat(textStyle: kHeadingStyle),
                ),
              ),
              Spacer(
                flex: 1,
              ),
              CrossFade(
                  initialData: '',
                  data: password,
                  builder: (value) {
                    return Text(
                      value,
                      style: GoogleFonts.sourceCodePro(
                          textStyle: kSubHeadingStyle),
                    );
                  }),
              Opacity(
                opacity: 0.5,
                child: RawMaterialButton(
                  splashColor: Colors.transparent,
                  padding: EdgeInsets.all(12),
                  onPressed: _copy,
                  child: Text(
                    'Copy',
                    style: GoogleFonts.montserrat(
                        textStyle: kSmallButtonTextStyle),
                  ),
                ),
              ),
              Spacer(
                flex: 1,
              ),
              RawMaterialButton(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(15)),
                splashColor: Colors.transparent,
                padding: EdgeInsets.all(12),
                fillColor: kAppPrimaryColor,
                onPressed: _generate,
                child: Text(
                  'Generate',
                  style: GoogleFonts.montserrat(textStyle: kButtonTextStyle),
                ),
              ),
              Spacer(
                flex: 2,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Okay, so the issue seemed to be the flutter_svg library.好的,所以问题似乎是 flutter_svg 库。 Not sure exactly why it was causing other text to scale oddly, but changing the way I render the image fixed the issue.不确定为什么它会导致其他文本奇怪地缩放,但改变我渲染图像的方式解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM