flutter AppLocalizations本地化= AppLocalizations.of(context)!;:表达式的计算结果不是函数,因此无法调用

jm2pwxwz  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(171)
Widget build(BuildContext context) {
AppLocalizations localizations =AppLocalizations.of(context)!;

我正在使用下面的builder下的这行,它是工作和一切都很好,但突然我得到了这个错误,我无法修复它。

Waiting for connection from debug service on Chrome...
.dart_tool/flutter_gen/gen_l10n/app_localizations.dart:490:14: Error: 'of' is already declared in this scope.
  String get of;
             ^^
.dart_tool/flutter_gen/gen_l10n/app_localizations.dart:67:28: Context: Previous declaration of 'of'.
  static AppLocalizations? of(BuildContext context) {
                           ^^
lib/screens/main-page/components/appbar.dart:25:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
                                                      ^^
lib/screens/shared_components/mskn_drawer.dart:18:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
                                                      ^^
lib/screens/main-page/components/search_field.dart:18:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
                                                      ^^
lib/screens/main-page/components/suggestion_list.dart:26:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
                                                      ^^
lib/screens/other/about_us.dart:16:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
                                                      ^^
lib/screens/other/connect_with_us.dart:19:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
                                                      ^^
lib/screens/main-page/components/buildings_cards.dart:23:55: Error: Can't use 'of' because it is declared more than once.
    AppLocalizations localizations = AppLocalizations.of(context)!;
   
```                                                    ^^
6za6bjd0

6za6bjd01#

我知道现在回答有点晚了,但问题是你在应用程序本地化文件中声明了一个名为“of”的变量,但flutter已经使用了“of”,所以它不能区分两者。
解决方案:例如,将变量“of”的名称更改为“ofText”。

相关问题