英文:
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 中进行了覆盖。
英文:
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: "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",
),
),
);
}
}
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论