Home > other >  build runner package in my flutter app for JSON serialization not working
build runner package in my flutter app for JSON serialization not working

Time:11-29

I'm using build_runner package in my flutter app for JSON serialization. I've correctly installed it in pubspec.yaml file under dev dependencies. but when I try to use flutter pub run build_runner build it releases the following.

    C:\Users\MoBix\Music\islamic_social_media>flutter pub run build_runner build
Unhandled exception:
Bad state: Unable to generate package graph, no `C:\Users\MoBix\Music\islamic_social_media\.dart_tool\flutter_gen\pubspec.yaml` found.
#0      _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:232:5)
#1      _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:206:21)
#2      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:101:33)
<asynchronous suspension>
#3      main (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-2.1.5/bin/build_runner.dart:27:30)
<asynchronous suspension>
pub finished with exit code 255

my pubspec.yaml

dev_dependencies:
  flutter_launcher_icons: ^0.9.2
  flutter_app_name: ^0.1.1
  build_runner:
  flutter_test:
    sdk: flutter

my flutter doctor -v

C:\Users\MoBix>flutter doctor -v
[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19043.1348], locale en-US)
    • Flutter version 2.5.3 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (6 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\MoBix\AppData\Local\Android\sdk
    • Platform android-Sv2, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10 0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10 0-b96-7249189)

[√] Connected device (2 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.45
    • Edge (web)   • edge   • web-javascript • Microsoft Edge 94.0.992.50

• No issues found!

What is the fix for this?

CodePudding user response:

It's interesting that it points to .dart_tool/flutter_gen/pubspec.yaml. This issue mentions this problem when generate: true is set in the pubspec.yaml.

If you don't need that, try removing it. Also, a flutter clean and flutter pub get might be necessary.

  • Related