Flag for UK countries give error in Flutter Flag package

huangapple go评论59阅读模式
英文:

Flag for UK countries give error in Flutter Flag package

问题

I'm using Flutter Flag package to show countries flags. When trying to specify for England, Wales, N-Ireland or Scotland flag, it returns the replacement flag.

Flag.fromString('gb-eng',
                    height: 18,
                    width: 18,
                    fit: BoxFit.fitWidth,
                    replacement: Container(
                      height: 18,
                      width: 18,
                      decoration: BoxDecoration(
                            image: const DecorationImage(
                            image: AssetImage(replacementFlag),
                            fit: BoxFit.contain,
                          )),
                    )),

I tried using the Flag.fromCode format too, and that doesn't work too. The gb works though.

How do I get the England flag?

英文:

I'm using Flutter Flag package to show countries flags. When trying to specify for England, Wales, N-Ireland or Scotland flag, it returns the replacement flag.

Flag.fromString('gb-eng',
                    height: 18,
                    width: 18,
                    fit: BoxFit.fitWidth,
                    replacement: Container(
                      height: 18,
                      width: 18,
                      decoration: BoxDecoration(
                            image: const DecorationImage(
                            image: AssetImage(replacementFlag),
                            fit: BoxFit.contain,
                          )),
                    )),

I tried using the Flag.fromCode format too, and that doesn't work too.
The gb works though.

How do I get the England flag?

答案1

得分: 1

看起来包中有一个错误。幸运的是,你可以直接在 flags 包中使用提供的资源。

#pubspec.yaml

name: temp
description: 一个新的Flutter项目。

publish_to: "none"

version: 1.0.0+1

environment:
  sdk: ">=2.19.2 <3.0.0"

dependencies:
  cupertino_icons: ^1.0.2
  flag: ^6.0.0
  flutter:
    sdk: flutter
  flutter_svg: ^2.0.1

dev_dependencies:
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter
dependency_overrides:
  flutter_svg: ^2.0.1

flutter:
  uses-material-design: true
// main.dart
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          useMaterial3: true,
        ),
        home: const MyHomePage());
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flag'),
      ),
      body: Center(
        child: SvgPicture.asset(
          "res/4x3/gb-eng.svg",
          package: "flag",
        ),
      ),
    );
  }
}

因为我们没有使用 Flags widget,所以我们不关心它依赖于哪个版本的 flutter_svg,因此在 pubspec.yaml 中进行了覆盖。

输出:
Flag for UK countries give error in Flutter Flag package

英文:

Looks like bug in the package. Fortunately, you can use provided resource in flags package directly.

#pubspec.yaml

name: temp
description: A new Flutter project.

publish_to: &quot;none&quot;

version: 1.0.0+1

environment:
  sdk: &quot;&gt;=2.19.2 &lt;3.0.0&quot;

dependencies:
  cupertino_icons: ^1.0.2
  flag: ^6.0.0
  flutter:
    sdk: flutter
  flutter_svg: ^2.0.1

dev_dependencies:
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter
dependency_overrides:
  flutter_svg: ^2.0.1

flutter:
  uses-material-design: true
// main.dart
import &#39;package:flutter/material.dart&#39;;
import &#39;package:flutter_svg/flutter_svg.dart&#39;;

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: &#39;Flutter Demo&#39;,
        theme: ThemeData(
          primarySwatch: Colors.blue,
          useMaterial3: true,
        ),
        home: const MyHomePage());
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(&#39;Flag&#39;),
      ),
      body: Center(
        child: SvgPicture.asset(
          &quot;res/4x3/gb-eng.svg&quot;,
          package: &quot;flag&quot;,
        ),
      ),
    );
  }
}

Since we are not using Flags widget, we don't case what version of flutter_svg it depended on hence overridden it in pubspec.yaml

Output:
Flag for UK countries give error in Flutter Flag package

huangapple
  • 本文由 发表于 2023年2月20日 00:38:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75501689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定