Michaeluuk
Michaeluuk

Reputation: 114

Flutter Error: Getter not found: 'wordPair' in english_words.dart package

i recently started learning flutter. I was working on the 'package:english_words/english_words.dart' package. I have successfully imported it by modifying the pubspec.yaml file by adding 'english_words: ^3.1.0 inside dependencies and on the main.dart file child:Text(wordPair.asPascalCase) is throwing an error. The output I got after running it is :

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

and here is my code:

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),
        ),
      ),
    );
  }
}

my english.dart file is

/// 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';

Upvotes: 3

Views: 4225

Answers (2)

Michaeluuk
Michaeluuk

Reputation: 114

The working code for this question is also available here

Upvotes: 2

snaipeberry
snaipeberry

Reputation: 1059

This file comes from the flutter package, you won't have to modify it.

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';

The problem is the understanding of the english_words package. Using wordPair makes no sense since you didn't declared it.

You can't access the asPascalCase getter with a static instance of WordPair. So you will have to create an instance of WordPair and then use the pascalCase getter.

import 'package:english_words/english_words.dart';

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

Upvotes: 4

Related Questions