flutter_diet 0.0.1 copy "flutter_diet: ^0.0.1" to clipboard
flutter_diet: ^0.0.1 copied to clipboard

The ultimate terminal-based Flutter App Size Analyzer & CI/CD size budget guard.

example/example.dart

import 'package:flutter_diet/flutter_diet.dart';

void main() async {
  print('🥦 Flutter Diet Library - Programmatic Usage Example\n');

  // 1. Define a mock JSON string representing build size analysis data.
  // This simulates the raw output produced by 'flutter build apk --analyze-size'.
  const mockJson = '''
  {
    "n": "Total Build Size",
    "v": 15728640,
    "children": [
      {
        "n": "Dart AOT",
        "v": 5242880,
        "children": [
          {"n": "package:flutter", "v": 3145728},
          {"n": "package:my_app", "v": 2097152}
        ]
      },
      {
        "n": "Assets",
        "v": 10485760,
        "children": [
          {"n": "assets/images/background.png", "v": 8388608},
          {"n": "assets/fonts/Roboto.ttf", "v": 2097152}
        ]
      }
    ]
  }
  ''';

  // 2. Parse the raw JSON content using SizeParser
  print('Step 1: Parsing build size analysis data string...');
  final SizeNode rootNode = SizeParser.parseString(mockJson);
  print(
    '✓ Tree parsed successfully. Root node: "${rootNode.name}" (${rootNode.humanSize})\n',
  );

  // 3. Define size budgets to check against programmatically
  final budgets = [
    SizeBudget(
      name: 'Total Build Size',
      maxSize: 20 * 1024 * 1024, // 20 MB budget
      rawMaxSize: '20MB',
    ),
    SizeBudget(
      name: 'Assets',
      maxSize:
          8 *
          1024 *
          1024, // 8 MB budget (this budget will fail because assets is 10 MB)
      rawMaxSize: '8MB',
    ),
  ];

  // 4. Run the budget guard checks programmatically
  print('Step 2: Checking budgets...');
  final guard = BudgetGuard();
  final allPassed = guard.checkBudgets(rootNode, budgets);

  print('\nStep 3: Verification complete. All budgets passed? $allPassed');
}
1
likes
160
points
33
downloads

Documentation

API reference

Publisher

verified publisherbechattaoui.dev

Weekly Downloads

The ultimate terminal-based Flutter App Size Analyzer & CI/CD size budget guard.

Homepage
Repository (GitHub)
View/report issues

Topics

#cli #size-analyzer #budget #ci-cd #app-size

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

args, mason_logger, path, yaml

More

Packages that depend on flutter_diet