4

Im having issues to get the desired output for my json file with the build_runner it runs successfully but isn't giving any outputs

my first.dart file

```
import 'package:json_annotation/json_annotation.dart';

part 'first.g.dart';


@JsonSerializable()
class User {
String visibility, name;
User(this.visibility, this.name);

 factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);


 Map<String, dynamic> toJson() => _$UserToJson(this);
}
```

Do my project need any buil.yaml file in my project?

my pubspec.yaml file

```
dependencies:
 flutter:
  sdk: flutter
 json_annotation: ^4.4.0
 http: ^0.13.4

dev_dependencies:
 flutter_test:
  sdk: flutter
 build_runner: ^2.1.7
 json_serializable: ^6.1.1
 ```

 

This is what my terminal looks like after execution of command

 flutter pub run build_runner build

terminal

 PS D:\Flutter\json_parse\learn> flutter pub run build_runner build
 [INFO] Generating build script...
 [INFO] Generating build script completed, took 359ms

 [INFO] Precompiling build script......
 [INFO] Precompiling build script... completed, took 7.0s

 [INFO] Initializing inputs
 [INFO] Building new asset graph...
 [INFO] Building new asset graph completed, took 758ms

 [INFO] Checking for unexpected pre-existing outputs....
 [INFO] Checking for unexpected pre-existing outputs. completed, took 1ms

 [INFO] Running build...
 [INFO] Generating SDK summary...
 [INFO] 3.5s elapsed, 0/3 actions completed.
 [INFO] Generating SDK summary completed, took 3.5s

 [INFO] 4.6s elapsed, 0/3 actions completed.
 [INFO] 5.6s elapsed, 0/3 actions completed.
 [INFO] 7.0s elapsed, 0/3 actions completed.
 [INFO] 12.9s elapsed, 1/3 actions completed.
 [INFO] Running build completed, took 13.6s

 [INFO] Caching finalized dependency graph...
 [INFO] Caching finalized dependency graph completed, took 30ms

 [INFO] Succeeded after 13.6s with 0 outputs (6 actions)

I'm not getting what is the problem in my code

James Z
  • 12,209
  • 10
  • 24
  • 44
  • how you are looking at the output? Did you write any code for...It`s running with the success though... – gretal Dec 17 '21 at 07:14
  • I am getting the json file through api and want to convert the json format to dart format so i can use the data in my application, I watched videos on YouTube about json serialization and tried to implement it but im not able to get output. There is no error and nor any json data output just the command runs successfully. – Karan Raghwani Dec 17 '21 at 07:38
  • you can refer here: [demo implemenation](https://medium.flutterdevs.com/automatic-generate-json-serializable-in-flutter-4c9d2d23ed88) . – gretal Dec 17 '21 at 07:39
  • Nothing changed still getting the same issue. Should I have a build.yaml file ? – Karan Raghwani Dec 17 '21 at 07:54
  • I think it is present on ```pubspec.yaml``` file. – gretal Dec 17 '21 at 07:57

5 Answers5

4

I've had this issue before. I observed that the build_runner output gave us 0 if the code was not saved before running build_runner. I therefore recommend that,

"Before running build runner, consider saving your changes of the data class."

2

Solved by

flutter clean
flutter packages pub run build_runner watch --delete-conflicting-outputs
Márcio Valim
  • 2,459
  • 3
  • 10
  • 21
0

Add this in pubspec.ymal file

dependencies:
  flutter:
    sdk: flutter
  hive: ^2.2.1
  path_provider: ^2.0.10
  json_annotation: ^3.0.0
  hive_flutter: ^1.0.0
  hive_generator: ^1.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^1.3.1
  json_serializable: ^3.2.2
lepsch
  • 8,927
  • 5
  • 24
  • 44
Vignesh M
  • 11
  • 1
  • As your snippet is YAML, please use code-block formatting to make its indentation clear. (I'd edit it for you, but I wouldn't trust myself to guess the proper indentation, which is critical for YAML.) – Derek T. Jones Jun 04 '22 at 18:07
0

Add "hive_generator: ^2.0.0" and "build_runner: ^2.3.2" to the "dev_dependencies:" section of the "pubspec.yaml" file.

And then use this command in the terminal: flutter packages pub run build_runner watch --use-polling-watcher --delete-conflicting-outputs

Aravind H
  • 1
  • 1
0

It's worth noting to check your pubspec.yaml spaces. I checked and found some are off set. It works after correcting them back in.

ghifari.akbar
  • 119
  • 1
  • 7