Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Installation Guide and Example. #41

Open
efroim102 opened this issue Sep 23, 2020 · 2 comments
Open

Update Installation Guide and Example. #41

efroim102 opened this issue Sep 23, 2020 · 2 comments

Comments

@efroim102
Copy link

efroim102 commented Sep 23, 2020

I was really struggling to get this project up and running since the Example had no indication that the rootBundle argument must be passed to TimeMachine.initialize nor does the actual method have it as a required parameter.

Secondly, once I figured that out I struggled some more with an additional asset loading error which after much debugging I found mentioned in the API Reference that 2 assets need to be listed in pubsec.yaml, there's no mention of this in the Installation Guide.

I'm going to add the 3 main errors I was dealing with down below so that others that have similar errors can finally figure out how this library needs to be set up (until the documentation is updated), If I have the time I'll try to create a PR myself.

  • Unhandled Exception: Exception: Pass in the rootBundle from 'package:flutter/services.dart';
  • Unhandled Exception: NoSuchMethodError: The method 'getJson' was called on null.
  • Unhandled Exception: Unable to load asset: packages/time_machine/data/tzdb/tzdb.bin

For easy copy-pasting here are the solutions:

Add to pubsec.yaml:

assets:
  - packages/time_machine/data/cultures/cultures.bin
  - packages/time_machine/data/tzdb/tzdb.bin

How to Initialize TimeMachine:

await TimeMachine.initialize({
  'rootBundle': rootBundle,
});
@SteveAlexander
Copy link
Collaborator

I see on the pub.dev page for time_machine, there is an example to initialize. But, it is incorrect:

import 'package:flutter/services.dart';

// TimeMachine discovers your TimeZone heuristically (it's actually pretty fast).
await TimeMachine.initialize({rootBundle: rootBundle});

It should instead have the rootBundle key quoted as a string:

import 'package:flutter/services.dart';

// TimeMachine discovers your TimeZone heuristically (it's actually pretty fast).
await TimeMachine.initialize({'rootBundle': rootBundle});

@HerrNiklasRaab
Copy link

If you do the initialization in the main method, make sure you call this before:

WidgetsFlutterBinding.ensureInitialized();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants