flutter build_runner giving 0 output after being executed
Asked Answered
N

8

7

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

Nunez answered 17/12, 2021 at 6:58 Comment(5)
how you are looking at the output? Did you write any code for...It`s running with the success though...Mullein
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.Nunez
you can refer here: demo implemenation .Mullein
Nothing changed still getting the same issue. Should I have a build.yaml file ?Nunez
I think it is present on pubspec.yaml file.Mullein
D
6

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,

1. Save Your Changes

Before running build_runner, ensure all changes to your data class files are saved

2. Include Appropriate Part File References

  • For json_serializable:

    part 'file_name.g.dart';

  • For freezed:

    part 'file_name.freezed.dart';

  • For json_serializable and freezed together:

    part 'file_name.freezed.dart';

    part 'file_name.g.dart';

Dre answered 23/8, 2022 at 10:23 Comment(2)
A very important note is that part file should be file_name exactly as it is, not class nameGlair
Absolutely... @MuhammedRefaatDre
S
2

Solved by

flutter clean
flutter packages pub run build_runner watch --delete-conflicting-outputs
Sounding answered 25/5, 2023 at 10:3 Comment(0)
E
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
Eudemonics answered 4/6, 2022 at 14:31 Comment(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.)Winner
S
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

Sherillsherilyn answered 15/11, 2022 at 11:22 Comment(0)
W
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.

Worrisome answered 14/4, 2023 at 6:25 Comment(0)
A
0
  1. Make sure your syntax for part is correct.

for json_serializable: part 'current_file_name.g.dart'; for freezed: part 'current_file_name.freezed.dart';

  1. Make sure you saved changes for the current file before running dart run build_runner build --delete-conflicting-outputs.
Accommodate answered 23/11, 2023 at 7:24 Comment(0)
C
0

try adding envied_generator in your pubsec.yaml file under dev_dependenciens. https://pub.dev/packages/envied_generator/install

Camaraderie answered 2/12, 2023 at 16:35 Comment(1)
K
0

If you're generating injectables. Make sure you also have injectable_generator in your dev_dependencies.

The frustrating thing about this issue is that no error occurs. Since you have build_runner, running dart run build_runner build will execute with no errors but 0 outputs. In my case, adding injectable_generator finally got my injectables injected! 🥳

Kellerman answered 17/12, 2023 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.