Closed KeidsID closed 11 months ago
I really like the chopper API after read the docs, but can't use it because of this.
If you want it dynamic simply use it like this
Future<Response<String>> getUserByEmail(
@Header() String? name, // <-- like this
) {}
And please, don't use this approach to handle auth. Use the dedicated authenticator interceptor for that.
I mean Dio didn't force const for the request headers.
Steps to Reproduce
SDKs & packages Versions
create dummy
.env
file on project root.create an obfuscate
Env
class.fetch dependencies then generate env.
try using the chopper API.
Expected results: No Error At All
Actual results: immutable for the [GET] annotation
Code sample
```dart import 'package:chopper/chopper.dart'; import 'package:envied/envied.dart'; import 'package:flutter/material.dart'; part 'main.chopper.dart'; part 'main.g.dart'; void main() { runApp(const MainApp()); } class MainApp extends StatelessWidget { const MainApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: Center( child: Text('Hello World!'), ), ), ); } } @Envied(obfuscate: true) abstract final class Env { @EnviedField(varName: 'API_KEY') static final String apiKey = _Env.apiKey; // it's final because there's a step to decrypt it. } mixin ClientHeaders on ChopperService { MapLogs
``` ``` ``` Analyzing chopper_headers_issue... error • lib\chopper_example.dart:13:17 • Arguments of a constant creation must be constant expressions. Try making the argument a valid constant, or use 'new' to call the constructor. • const_with_non_constant_argument error • lib\chopper_example.dart:14:28 • The body might complete normally, causing 'null' to be returned, but the return type, 'Future