[Bug]: PackageInfo needs HttpClient but has no parameter for it
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start at the package_info_plus web implementation and the PackageInfo.fromPlatform entry point, then reproduce the reported command with no_default_http_client=true. The work is done when a caller can provide its custom Client and the web build no longer raises the reported missing-client error; add or update coverage for that behavior if the package has relevant tests.
Written by the indexing model from the issue text.
Description
Platform
Web
Plugin
package_info_plus
Version
8.1.1
Flutter SDK
3.24.3
Steps to reproduce
Hello,
based on this issue, I added a minimal sample code. The problem is, that the user has their own customHttpClient, which the user uses in the app. Therefore the user sets the no_default_http_client=true flag, but package_info_plus needs a httpClient, but has no parameter to set the httpClient.
Add package_info_plus: ^8.1.1 and http: ^1.2.2 to the pubspec.yml
Build with flutter build web --release --source-maps --dart-define=no_default_http_client=true
And run with python3 -m http.server 8089
Code Sample
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:package_info_plus/package_info_plus.dart';
late final PackageInfo packageInfo;
late final Response response;
void main() async {
response = await customHttpClient().get(Uri.parse("foo"));
packageInfo = await PackageInfo.fromPlatform();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
children: [
Text("packageInfo.packageName: ${packageInfo.packageName}"),
Text("response.body: ${response.body}"),
],
),
),
),
);
}
}
class customHttpClient implements Client {
@override
void close() {}
@override
Future<Response> delete(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<Response> get(Uri url, {Map<String, String>? headers}) async {
return Response("foo", 200);
}
@override
Future<Response> head(Uri url, {Map<String, String>? headers}) async {
return Response("foo", 200);
}
@override
Future<Response> patch(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<Response> post(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<Response> put(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<String> read(Uri url, {Map<String, String>? headers}) async {
return "foo";
}
@override
Future<Uint8List> readBytes(Uri url, {Map<String, String>? headers}) async {
return Uint8List(0);
}
@override
Future<StreamedResponse> send(BaseRequest request) async {
return StreamedResponse(Stream.empty(), 200);
}
}
Logs
Uncaught Error: Bad state: no_default_http_client was defined but runWithClient was not used to configure a Client implementation.
at Object.e (js_helper.dart:1198:19)
at Object.ahp (browser_client.dart:23:5)
at Object.aa1 (client.dart:42:37)
at http.dart:165:16
at Yj.a (async_patch.dart:303:19)
at Yj.$2 (async_patch.dart:328:23)
at Object.N (async_patch.dart:233:3)
at Object.agT (http.dart:165:7)
at Object.a0u (http.dart:165:7)
at Object.ahL (http.dart:49:5)
Flutter Doctor
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.1.1 24B91 darwin-arm64, locale en-AT)
• Flutter version 3.24.3 on channel stable at /Users/martin/fvm/versions/3.24.3
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (3 months ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at /Users/martin/Library/Android/sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16B40
• CocoaPods version 1.16.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.1)
• Android Studio at /Applications/Android Studio.app/Contents
• 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 17.0.11+0-17.0.11b1207.24-11852314)
[✓] VS Code (version 1.95.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.102.0
[✓] Connected device (3 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.1.1 24B91 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.1.1 24B91 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.86
[✓] Network resources
• All expected network resources are available.
Checklist before submitting a bug
- I searched issues in this repository and couldn't find such bug/problem
- I Google'd a solution and I couldn't find it
- I searched on StackOverflow for a solution and I couldn't find it
- I read the README.md file of the plugin
- I'm using the latest version of the plugin
- All dependencies are up to date with
flutter pub upgrade - I did a
flutter clean - I tried running the example project
- Dominant language
- Dart
- Stars
- 1.9k
- Forks
- 1.3k
- Avg merge
- 6d 16h
- Merged PRs (30d)
- 16
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fluttercommunity/plus_plugins
-
bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
fluttercommunity/plus_plugins#3994 ·
Maintainers usually reply within 1 day
-
[package_info_plus]: Use Flutter's compile-time build name/number on web instead of version.jsonOpen
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
fluttercommunity/plus_plugins#3989 ·
Maintainers usually reply within 1 day
-
enhancement triage
Difficulty 4/5 3-5 days Newbie friendliness 55/100
fluttercommunity/plus_plugins#3976 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
fluttercommunity/plus_plugins#3974 · 1 reaction ·
Maintainers usually reply within 1 day
-
enhancement triage
Difficulty 5/5 Over a week Newbie friendliness 48/100
fluttercommunity/plus_plugins#3973 ·
Maintainers usually reply within 1 day
All issues in fluttercommunity/plus_plugins
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Nutrition editor unit dropdown ignores selected value, applies wrong unit (silent data corruption)Opennutrition facts
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
openfoodfacts/smooth-app#7812 · 3 comments ·
Maintainers usually reply within 1 day
-
P1
Difficulty 1/5 Under an hour Newbie friendliness 90/100
dart-lang/native#3722 · 1 comment · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 3 days