Closed ronymesquita closed 2 years ago
I suspect this code should be a new package, liketimezone_manager
or something. It exclusively provides new libraries and new features without relying on internal implementation of the package.
I cannot add a dependency on flutter in this package because it is used outside Flutter.
If your main idea is using Flutter with one configuration, you can use this instead:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
tz.initializeDatabase(Uint8List.sublistView(
await rootBundle.load('packages/timezone/data/latest_all.tzf')));
runApp(MyApp());
}
This will work on all platforms including web.
Also updating dependencies' minor or patch versions is not needed, because ^
is used.
Hello.
The @untp code is simple and it works. It might be better to just edit the README.md
to indicate how to configure Flutter. Is needed to add an asset to pubspec.yaml
and put a few lines in the main
method.
The idea really is use Flutter with one configuration.
Why is this required at all? For me it works on macOS, Web, iOS and Android when using:
import 'package:timezone/data/latest_10y.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
initializeTimeZones();
runApp(App());
}
initializeTimeZones()
method uses embedded data in the dart code. It increases dart snapshot/js size. It is fine if it is used on mobile and desktop. But on web, web page loads slower due to increased dart code size. With rootBundle method, timezone data can be loaded as async, so loading will be faster.
But if you initialize in main(), there should not be huge difference. runApp
waits the initialize call, it doesn't matter data loaded with rootBundle or embedded in the dart code.
If your app uses timezone data occasionally and initializes the data outside of main(), it would be better to use rootBundle.
Thanks for the explanation. Makes a lot of sense. Would be great to have this in the README.
Also, additionally, it should tell that you then have to add packages/timezone/data/latest_all.tzf
to the assets in pubspec.yml
.
Changes
flutter
as a dependency inpubspec.yaml
TimezoneManager
to use with Flutter applicationREADME.md
pubspec.yaml
Notes
flutter
inpubspec.yaml
requires some tests to be made withdart
command and some with useflutter
command.Objective
The main ideia is use Flutter with one configuration. The code of this pull request was tested on Android, iOS, web and Ubuntu (Linux).