plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: App name on web isn't taken from `manifest.json`

Open OutdatedGuy opened this issue 3 years ago • 12 comments

Platform

Web

Plugin

package_info_plus

Version

1.4.2

Flutter SDK

3.0.5

Steps to reproduce

  1. Run sample code
  2. See app name for web is same as package name

Code Sample

// Flutter Packages
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
        useMaterial3: true,
      ),
      home: const MyLicensePage(),
    );
  }
}

class MyLicensePage extends StatefulWidget {
  const MyLicensePage({Key? key}) : super(key: key);

  @override
  State<MyLicensePage> createState() => _MyLicensePageState();
}

class _MyLicensePageState extends State<MyLicensePage> {
  PackageInfo? packageInfo;

  Future<void> _getPackageInfo() async {
    packageInfo = await PackageInfo.fromPlatform();
    setState(() {});
  }

  @override
  void initState() {
    super.initState();
    _getPackageInfo();
  }

  @override
  Widget build(BuildContext context) {
    return LicensePage(
      key: ValueKey(packageInfo),
      applicationIcon: Container(
        margin: const EdgeInsets.all(10),
        decoration: BoxDecoration(
          // image: const DecorationImage(
          //   image: AssetImage('assets/icons/launcher_icon_border.png'),
          //   fit: BoxFit.cover,
          // ),
          borderRadius: BorderRadius.circular(35),
          boxShadow: [
            BoxShadow(
              color: (Theme.of(context).brightness == Brightness.dark
                      ? Colors.white
                      : Colors.black)
                  .withOpacity(0.69),
              blurRadius: 10,
            ),
          ],
        ),
        width: 150,
        height: 150,
      ),
      applicationName: packageInfo?.appName,
      applicationVersion: packageInfo?.version,
      applicationLegalese: 'Copyright © 2022 OutdatedGuy',
    );
  }
}

Logs

Please refer to this issue: https://github.com/flutter/flutter/issues/108701

Flutter Doctor

[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22622.440], locale en-IN)
    • Flutter version 3.0.5 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (3 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at C:\Users\Dell\AppData\Local\Android\sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.2.32526.322
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] VS Code (version 1.69.2)
    • VS Code at C:\Users\Dell\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.44.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22622.440]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 103.0.5060.134
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 103.0.1264.77

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

OutdatedGuy avatar Aug 10 '22 10:08 OutdatedGuy

Hey! Can I take this issue? @mhadaily

alfredobs97 avatar Oct 10 '22 18:10 alfredobs97

Go ahead, please

mhadaily avatar Oct 10 '22 18:10 mhadaily

I checked the issue and the package, but does make sense that the app name will fetch from manifest.json (PWA configuration, most of cases, Flutter developers won't fulfilled this info) instead of the standard name in pubspec.yaml ? @mhadaily

alfredobs97 avatar Oct 10 '22 18:10 alfredobs97

Well, when a flutter project is created, the package name is used for name and short name properties in the manifest.json file.

So if we take name from manifest file, then even if the developer didn't set any name the default package name will be used. So same behaviour as now we'll see.

But if they configured the name property in manifest file, then the new name will be used and that's what I want.

OutdatedGuy avatar Oct 11 '22 04:10 OutdatedGuy

The web implementation of package_info_plus reads the app_name property from the version.json which is generated by Flutter based on the pubspec.yaml.

IMO, If you want to read the name from another file, then you need to implement that on your side.

miquelbeltran avatar Oct 11 '22 07:10 miquelbeltran

IMO, If you want to read the name from another file, then you need to implement that on your side.

How to do that?

The web implementation of package_info_plus reads the app_name property from the version.json which is generated by Flutter based on the pubspec.yaml.

I understand, that's why my above comment specifies that using name property form manifest file would act the same in normal scenario and better in custom scenarios.

OutdatedGuy avatar Oct 11 '22 17:10 OutdatedGuy

How to do that?

You can take a look at how the app_name is read from the version.json file and implement the same functionality for any other file.

using name property form manifest file would act the same in normal scenario and better in custom scenarios.

Can you explain why it is preferable that the package information is read from the manifest.json instead of the version.json, because I don't see the advantage?

The version.json is generated by the Flutter framework, and it is shipped together with the app. Running flutter run -d chrome will generate a version.json and will work out of the box.

The manifest.json is not generated by flutter run, you can try that, and you will see that accessing localhost/manifest.json returns the following:

{"info":"manifest not generated in run mode."}

IMO, if you want to read specific information from the manifest.json, then you need to implement your own parsing code.

miquelbeltran avatar Oct 11 '22 19:10 miquelbeltran

I would like to vouch for the manifest.json file. We, for example, used it in our project and it is indeed different from the pubspec.yaml package name.

Bungeefan avatar Oct 12 '22 18:10 Bungeefan

We cannot read app name from manifest. The manifest file can be ignored or deleted if you opt out of PWA. The version.json is the standard Flutter way that guarantees consistency with the entire ecosystem.

mhadaily avatar Oct 12 '22 19:10 mhadaily

I use flavors to create builds for different environments, and for Android and iOS, there are ways to define the app name in separate files accessed by those flavors - therefore, the pubspec.yaml 'name' field is never used.

I would like to be able to change the app name for web too, based on environment/flavor. I know flavors are not supported (and there don't appear to be plans to do so, oddly), but as a work-around, I can create different version.json files for each environment so that the PWA has different names, but I cannot do that for the plain web version, as it will only ever use the single name definition in pubspec.yaml.

As I use the appName from PackageInfo in my About dialog, I cannot distinguish the About dialog between environments. If version.json could used if available, it would solve my problem, but I am open to other solutions you may have to offer too.

AndrewStickler avatar Mar 31 '23 15:03 AndrewStickler

From what I understand from the previous comments, it seems that there is no way to differentiate the app name from the package name on web as there are no way to custom the generated version.json file.

On all other platforms, I am able to customize the appName parameter provided by the package_info plugin by changing values in different configuration files. However, on web, there doesn't seem to be a way to customize this identifier and differentiate it from the package name.

Let's say that you need a unique identifier for your app that is different from the name given in the pubspec.yaml file, and you want it to be cross-platform. You can manage to do this on all platforms except for web.

This is exactly the problem I am facing: all my app identifications on my backend are using this value, which is configured to be the Android bundle ID for all platforms (iOS/Windows), but I can't manage to do it on web.

Of course, there are ways to handle it differently on my end, and that's what I'm going to do. However, I think the package could be improved by providing information from a configuration file that can be customized by the user.

chedwin41 avatar May 04 '23 14:05 chedwin41

Yo @mhadaily, true that manifest is not the standard file, but we still can do this:

  1. Check if manifest file is present, if it is, then use data from there.
  2. Else, use the normal/original way of version.json file

OutdatedGuy avatar Dec 11 '23 17:12 OutdatedGuy