Why hard coded values were not increase the size of the flutter app?

312 Views Asked by At

I use 20 MB of text as String data inside a flutter Text() widget, But it did not increase the release app size.

APK size before adding 20MB of text data = 5.4MB

APK size After adding 20MB of text data = 5.4MB

(Note:- text data is not an unused value, It's used inside a flutter Text() widget)

Can I know, how flutter source code compression works or any information about this?

1

There are 1 best solutions below

1
On

My guess is that the Dart language, and by extension Flutter, use powerful data compression algorithms that are built into the language by default, but there are also additional plugins.

All I could find:

  1. An article on the "Medium" website about data compression
  2. Some info about compression
  3. Plugin for data compression
  4. Dart Api Dev GZip included by default in language

Maybe with the help of this information you will find what you are looking for. And by the way, compare the sizes of installed applications, for sure an application with 20 MB of text will weigh more in its installed form.

Example code of powerful compression:

import 'dart:io';
import 'dart:convert';

main(List<String> arguments) {
  String data = '';
  for (int i = 0; i < 100000; i++) {
    data = data + 'Hello world\r\n';
  }

  //Original Data
  List<int> original = utf8.encode(data);

  //Compress data
  List<int> compressed = gzip.encode(original);

  //Decompress
  List<int> decompress = gzip.decode(compressed);

  print('Original ${original.length} bytes');
  print('Compressed ${compressed.length} bytes');
  print('Decompressed ${decompress.length} bytes');

  String decoded = utf8.decode(decompress);
  assert(data == decoded);
}

Output:
Original 1300000 bytes
Compressed 2572 bytes
Decompressed 1300000 bytes