flutter_app_size_reducer 1.0.3
flutter_app_size_reducer: ^1.0.3 copied to clipboard
A Flutter plugin for analyzing and reducing app size through CLI commands.
import 'package:flutter/material.dart';
import 'package:flutter_app_size_reducer/flutter_app_size_reducer.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the package
await FlutterAppSizeReducer.init();
final results = await FlutterAppSizeReducer.analyze();
print('Unused assets: ${results['unusedAssets']}');
print('Large assets: ${results['largeAssets']}');
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App Size Reducer Example',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: const Text('App Size Reducer Example'),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
// Analyze assets
final results = await FlutterAppSizeReducer.analyze();
print('Analysis results: $results');
},
child: const Text('Analyze Assets'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
// Clean unused assets
await FlutterAppSizeReducer.clean(dryRun: true);
},
child: const Text('Clean Assets (Dry Run)'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
// Optimize assets
await FlutterAppSizeReducer.optimize(quality: 80);
},
child: const Text('Optimize Assets'),
),
],
),
),
);
}
}