0

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?

dev.bojack
  • 753
  • 5
  • 9

1 Answers1

1

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

Output: Output

Rahul
  • 3,529
  • 1
  • 5
  • 19