assets_codegen 2.1.1 assets_codegen: ^2.1.1 copied to clipboard
Code generator for assets plugin. Using this with assets_annotation package and one of @AstHelp, @IntlHelp annotations. More info at README.md
import 'package:assets_example/localization/localization_delegate.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
LocalizationDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('ru'),
],
title: 'Assets demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
Widget _buildText(String text) {
return Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Text(text, textAlign: TextAlign.center),
);
}
@override
Widget build(BuildContext context) {
final LocalizationMessages _loc = Messages.of(context);
return Scaffold(
appBar: AppBar(
title: Text('${Messages.of(context).book(1)} app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildText('You have $_counter ${_loc.book(_counter)}'),
_buildText('Namespaced title: ${_loc.namespacedZone.title}'),
_buildText('Checkout from one namespace: ${_loc.namespacedZone.checkout.title}'),
_buildText('Checkout from other namespace: ${_loc.cart.checkout.title}'),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}