简体   繁体   English

注解必须是 const 变量引用或 const 构造函数调用

[英]Annotation must be either a const variable reference or const constructor invocation

i had a error;我有一个错误; Annotation must be either a const variable reference or const constructor invocation.dart(invalid_annotation) The name 'Headers' is defined in the libraries 'package:dio/src/headers.dart (via package:dio/dio.dart)' and 'package:retrofit/http.dart'.注释必须是 const 变量引用或 const 构造函数 invocation.dart(invalid_annotation) 名称“Headers”在库“package:dio/src/headers.dart”中定义(通过 package:dio/dio.dart)包:改造/http.dart'。 Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.尝试对其中一个导入指令使用“作为前缀”,或者对除一个导入之外的所有指令隐藏名称。

I want to pass a jwt token.我想传递一个 jwt 令牌。 But i cant pass it through Headers because i get errors但我不能通过标头传递它,因为我收到错误

// import 'dart:convert';
// import 'dart:io';
// import 'package:amc_new/model/client_amc.dart';
// import 'package:http/http.dart' as http;
// import 'package:flutter_config/flutter_config.dart';

// String uri = FlutterConfig.get('API_URL');

// class ClientAmcService {
//   // ignore: missing_return
//   Future<ClientAmc> getclientAmc(String amcNo) async {
//     try {
//       var response = await http.get(
//         uri + '/report/getamcreport/$amcNo',
//         headers: {
//           HttpHeaders.authorizationHeader: 'jwt',
//         },
//       );
//       print("------------------------------------------------");
//       if (response.statusCode == 200) {
//         print(response.body);
//         print(response.statusCode);
//         print("------------------------------------------------");
//         List<ClientAmc> clientAmcFromJson(String str) => List<ClientAmc>.from(
//             json.decode(str).map((x) => ClientAmc.fromJson(x)));
//         List<ClientAmc> clientamclist = clientAmcFromJson(response.body);
//         return clientamclist[0];
//       } else {
//         print("Not Found");
//       }
//     } catch (e) {
//       print(e.toString());
//     }
//   }
// }

import 'package:amc_new/model/client_amc.dart';
import 'package:dio/dio.dart';
import 'package:retrofit/http.dart';

part 'amc_client_service.g.dart';

@RestApi()
abstract class ClientAmcService {
  factory ClientAmcService(Dio dio, {String baseUrl}) = _ClientAmcService;

  @GET('/report/getamcreport/{amcNo}')
  @Headers(<String, dynamic>{
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': 'Bearer {jwt}',
  })
  Future<ClientAmc> getclientAmc(@Path('amcNo') String amcNo);
}

I solved 'hide'.我解决了“隐藏”。 https://dart.dev/guides/language/extension-methods#api-conflicts https://dart.dev/guides/language/extension-methods#api-conflicts

import 'package:dio/dio.dart' hide Headers;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 const 变量必须用常量值初始化 || const vs var || 扑 - const variable must be initialized with a constant value || const vs var || flutter Flutter 错误 - 如何解决:被调用的构造函数不是 const 构造函数。 尝试从构造函数调用中删除“const” - Flutter Error - how to solve: The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation Flutter必须初始化const变量&#39;IconData&#39; - Flutter The const variable 'IconData' must be initialized 被调用的构造函数不是 const 构造函数。 尝试从构造函数调用中删除“const”。 Flutter怎么解决? - The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation. Flutter How to solve? 更喜欢带有常量构造函数的 const - prefer const with constant constructor flutter const 构造函数错误 - flutter const constructor error const 构造函数和 no_const 构造函数有什么区别? - What's the difference between const constructor and no_const constructor? Dart:使用const构造函数有不利之处吗? - Dart: Is there a disadvantage to using const constructor? Dart const 构造函数 - 它可以是默认的吗? - Dart const constructor - could it be default? 被调用的构造函数不是 const 构造函数 - The constructor being called isn't a const constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM