'Widget assets are not loaded on aws ec2 server

We are creating a new widget with the timezone package(https://pub.dev/packages/timezone), and the time zone package asset is not loaded on aws ec2 server and it was working correctly on other servers.

Steps to Reproduce

  1. Configure and run the sample on aws ec2 server
  2. It makes an error while loading the timezone package asset

Expected results:

  • Package asset will load correctly on aws ec2 server

Actual results:

  • Package asset not loaded correctly on aws ec2 server

Code sample


@override
  void initState() {
    _loadDataBase();
    super.initState();
  }

  Future<bool> _loadDataBase() async {
    final ByteData byteData =
    await rootBundle.load('packages/timezone/data/2020a.tzf');
    initializeDatabase(byteData.buffer.asUint8List());
    return true;
  }

  void _refresh() {
    DateTime date = DateTime.now();
    Location location = getLocation('Australia/Darwin');
    DateTime convertedDate = TZDateTime.from(date, location);
    print(convertedDate);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(

        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _refresh,
        tooltip: 'Convert Date',
        child: const Icon(Icons.refresh),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

Error log:


Uncaught Unable to load asset: packages/timezone/data/2020a.tzf

Screenshot:

Screen Shot 2022-04-22 at 4 47 38 PM

Sample: flutter_timezone.zip



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source