asset_helper 1.0.6
asset_helper: ^1.0.6 copied to clipboard
A Flutter package that automatically generates reference files for assets in a Flutter project
example/lib/main.dart
import 'package:flutter/material.dart';
// After running "flutter pub run asset_helper:generate", you'll be able to import:
// import 'generated/assets.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Asset Helper Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Asset Helper Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Example App for Asset Helper',
style: TextStyle(fontSize: 18),
),
const SizedBox(height: 20),
const Text(
'After running the asset generator, you can use:',
style: TextStyle(fontSize: 16),
),
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'Image.asset(Assets.IconsHomeSVG)',
style: TextStyle(
fontFamily: 'monospace',
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'// For a PNG file at assets/images/logo.png',
style: TextStyle(
fontFamily: 'monospace',
),
),
),
const SizedBox(height: 5),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'Image.asset(Assets.ImagesLogoPNG)',
style: TextStyle(
fontFamily: 'monospace',
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// Here you would use generated asset references
// if you had real assets in the project
},
child: const Text('Use Assets'),
),
],
),
),
);
}
}