auto_gen_assets 1.0.5
auto_gen_assets: ^1.0.5 copied to clipboard
A Flutter package for automatically generating strongly-typed asset references from your assets directory.
import 'package:flutter/material.dart';
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: 'Auto Gen Assets Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Auto Gen Assets 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(
'Assets loaded successfully!',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
const Text(
'Generated asset paths:',
style: TextStyle(fontSize: 18),
),
const SizedBox(height: 10),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Images: ${Assets.images.logo}'),
Text('Animations: ${Assets.animations.loading}'),
Text('Fonts: ${Assets.fonts.roboto}'),
],
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// This would normally load the actual assets
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Asset paths are ready to use!'),
),
);
},
child: const Text('Test Asset Loading'),
),
],
),
),
);
}
}