gpt4 book ai didi

Flutter报错: Getter not found: 'wordPair' in english_words. dart包

转载 作者:行者123 更新时间:2023-12-03 02:50:26 29 4
gpt4 key购买 nike

我最近开始学习 flutter。我正在研究“package:english_words/english_words.dart”包。我通过在依赖项中添加 'english_words: ^3.1.0 修改 pubspec.yaml 文件成功导入它,并且在 main.dart 文件 child:Text(wordPair.asPascalCase) 上抛出错误。运行后得到的输出是:

Compiler message: lib/main.dart:17:23: Error: Getter not found: 'wordPair'.

Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed.

FAILURE: Build failed with an exception.

  • Where: Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780

  • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'. Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

这是我的代码:

import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: Text(wordPair.asPascalCase),
),
),
);
}
}

我的english.dart文件是

/// Support for working with English text.
library english_words;

export 'src/syllables.dart';
export 'src/word_pair.dart';
export 'src/words/adjectives.dart';
export 'src/words/all.dart';
export 'src/words/nouns.dart';

最佳答案

该文件来自flutter包,您无需修改​​。

library english_words;

export 'src/syllables.dart';
export 'src/word_pair.dart';
export 'src/words/adjectives.dart';
export 'src/words/all.dart';
export 'src/words/nouns.dart';

问题是对english_words包的理解。使用 wordPair 没有任何意义,因为您没有声明它。

您不能使用 WordPair 的静态实例访问 asPascalCase getter。因此,您必须创建一个 WordPair 实例,然后使用 pascalCase getter。

import 'package:english_words/english_words.dart';

var wordpair = WordPair("first,", "second");
String pascalCase = wordpair.asPascalCase;

关于Flutter报错: Getter not found: 'wordPair' in english_words. dart包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60352463/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com