Skip to content

How to read ndjson file in assets folder #1

@jesscmoore

Description

@jesscmoore

I would like to use ndjson package to read a large ndjson file stored in the assets folder of my flutter app.

As a simple example I have copied your object.ndjson to assets/data folder. Here are relevant code parts:

pubspec.yaml:

flutter:

  assets:
    - assets/data/

main.dart:

import 'package:flutter/services.dart';
import 'package:ndjson/ndjson.dart';

...

void fetchData() async {
  final ndjsonSource = await rootBundle.loadString("assets/data/object.ndjson");

  final Stream<NdjsonLine> ndjson = ndjsonSource.parseNdjson();

  ...

}

This has the issue that "The method 'parseNdjson' isn't defined for the type 'String'..." because parseNdjson expects a stream. How can I use your ndjson flutter package to read a file in the assets folder?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions