icapps_architecture 1.0.0 icapps_architecture: ^1.0.0 copied to clipboard
icapps architecture components for flutter projects. Contains commonly used code for logging, extensions, ...
import 'package:example/theme/theme.dart';
import 'package:example/util/locale/localization.dart';
import 'package:example/util/locale/localization_delegate.dart';
import 'package:example/viewmodel/counter_viewmodel.dart';
import 'package:example/widget/provider/provider_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:icapps_architecture/icapps_architecture.dart';
L _getLocale<L>(BuildContext context) => Localization.of(context) as L;
T _getTheme<T>(BuildContext context) => AppTheme.of(context) as T;
void main() {
localizationLookup = _getLocale;
themeLookup = _getTheme;
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
localizationsDelegates: [
LocalizationDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({
required this.title,
Key? key,
}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return ProviderWidget<CounterViewModel>(
create: () => CounterViewModel(),
childBuilderWithViewModel: (context, viewModel, theme, localization) =>
Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${viewModel.current}',
style: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: theme.baseColor),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: viewModel.onIncrementTapped,
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}