flutter_app_size_reducer 0.0.1
flutter_app_size_reducer: ^0.0.1 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() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App Size Reducer Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Map<String, dynamic>? _appSize;
Map<String, dynamic>? _analysis;
bool _isOptimizing = false;
Future<void> _getAppSize() async {
final size = await FlutterAppSizeReducer.getAppSize();
setState(() {
_appSize = size;
});
}
Future<void> _analyzeAppSize() async {
final analysis = await FlutterAppSizeReducer.analyzeAppSize();
setState(() {
_analysis = analysis;
});
}
Future<void> _optimizeAppSize() async {
setState(() {
_isOptimizing = true;
});
try {
final success = await FlutterAppSizeReducer.optimizeAppSize({
'removeUnusedAssets': true,
'optimizeImages': true,
'removeUnusedDependencies': true,
});
if (success) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('App size optimization successful!')),
);
}
} finally {
setState(() {
_isOptimizing = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter App Size Reducer Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _getAppSize,
child: const Text('Get App Size'),
),
if (_appSize != null)
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('App Size: $_appSize'),
),
ElevatedButton(
onPressed: _analyzeAppSize,
child: const Text('Analyze App Size'),
),
if (_analysis != null)
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Analysis: $_analysis'),
),
ElevatedButton(
onPressed: _isOptimizing ? null : _optimizeAppSize,
child: _isOptimizing
? const CircularProgressIndicator()
: const Text('Optimize App Size'),
),
],
),
),
);
}
}