Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class MyApp extends StatelessWidget {
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
theme: ThemeData(
primarySwatch: Colors.blue,
),
theme: ThemeData(primarySwatch: Colors.blue),
home: MyHomePage(),
routes: {
'touch': (context) => TouchScreen(),
Expand All @@ -47,16 +45,12 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatelessWidget {
MyHomePage({
super.key,
});
MyHomePage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo Home Page'),
),
appBar: AppBar(title: Text('Flutter Demo Home Page')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
15 changes: 5 additions & 10 deletions example/lib/screen/counter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@ class CounterScreen extends StatelessWidget {
create: () => CounterViewModel(),
childBuilderWithViewModel: (context, viewModel, theme, localization) =>
Scaffold(
appBar: AppBar(
title: Text('Counter'),
),
appBar: AppBar(title: Text('Counter')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text('You have pushed the button this many times:'),
Text(
'${viewModel.current}',
style: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: theme.baseColor),
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
color: theme.baseColor,
),
),
],
),
Expand Down
15 changes: 5 additions & 10 deletions example/lib/screen/logger_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,21 @@ class LoggerScreen extends StatelessWidget {
create: () => LoggerViewModel()..init(),
childBuilderWithViewModel: (context, viewModel, theme, localization) =>
Scaffold(
appBar: AppBar(
title: Text('Logger test'),
),
appBar: AppBar(title: Text('Logger test')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 32),
child: Text(
'Log: ${viewModel.logLine}',
),
child: Text('Log: ${viewModel.logLine}'),
),
const SizedBox(height: 16),
Text(
'${viewModel.current}',
style: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: theme.baseColor),
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
color: theme.baseColor,
),
),
],
),
Expand Down
10 changes: 3 additions & 7 deletions example/lib/screen/stream_builder_test_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ class StreamBuilderTestScreen extends StatelessWidget {
create: () => StreamTestViewModel()..init(),
childBuilderWithViewModel: (context, viewModel, theme, localization) =>
Scaffold(
appBar: AppBar(
title: Text('Counter'),
),
appBar: AppBar(title: Text('Counter')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text('You have pushed the button this many times:'),
StreamBuilder(
stream: viewModel.counterStream,
builder: (context, snapshot) => Text(
Expand All @@ -34,7 +30,7 @@ class StreamBuilderTestScreen extends StatelessWidget {
TextButton(
onPressed: viewModel.addStream,
child: Text('Add stream'),
)
),
],
),
),
Expand Down
17 changes: 6 additions & 11 deletions example/lib/screen/stream_test_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,22 @@ class StreamTestScreen extends StatelessWidget {
create: () => StreamTestViewModel()..init(),
childBuilderWithViewModel: (context, viewModel, theme, localization) =>
Scaffold(
appBar: AppBar(
title: Text('Counter'),
),
appBar: AppBar(title: Text('Counter')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text('You have pushed the button this many times:'),
Text(
'${viewModel.current}',
style: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: theme.baseColor),
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
color: theme.baseColor,
),
),
TextButton(
onPressed: viewModel.addStream,
child: Text('Add stream'),
)
),
],
),
),
Expand Down
71 changes: 25 additions & 46 deletions example/lib/screen/touch_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class TouchScreen extends StatefulWidget {

class _TouchScreenState extends State<TouchScreen> {
Map<Color, int> _counters = Colors.primaries.asMap().map(
(key, value) => MapEntry(
value,
0,
),
(key, value) => MapEntry(value, 0),
);

bool forceAndroid = false;
Expand All @@ -29,9 +26,7 @@ class _TouchScreenState extends State<TouchScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Touch'),
),
appBar: AppBar(title: Text('Touch')),
body: Center(
child: ListView(
children: [
Expand Down Expand Up @@ -67,33 +62,24 @@ class _TouchScreenState extends State<TouchScreen> {
Text('Is Dark'),
],
),
Center(
child: Text(
'You have pushed the buttons this many times:',
),
),
..._counters.entries.map(
(entry) {
final color = entry.key;
final count = entry.value;
return Center(
child: TouchFeedBack(
onTapped: () {},
child: Text(
'0x${color.toARGB32().toRadixString(16).padLeft(8, '0')}: $count',
style: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: color),
),
Center(child: Text('You have pushed the buttons this many times:')),
..._counters.entries.map((entry) {
final color = entry.key;
final count = entry.value;
return Center(
child: TouchFeedBack(
onTapped: () {},
child: Text(
'0x${color.toARGB32().toRadixString(16).padLeft(8, '0')}: $count',
style: Theme.of(
context,
).textTheme.headlineMedium!.copyWith(color: color),
),
);
},
),
),
);
}),
const SizedBox(height: 16),
Center(
child: _createButtons(_counters),
),
Center(child: _createButtons(_counters)),
const SizedBox(height: 16),
Padding(
padding: EdgeInsets.all(16),
Expand All @@ -103,19 +89,13 @@ class _TouchScreenState extends State<TouchScreen> {
TouchFeedBack(
forcePlatform: _forcePlatform,
onTapped: () {},
child: Icon(
Icons.plus_one,
size: 32,
),
child: Icon(Icons.plus_one, size: 32),
),
const SizedBox(width: 8),
TouchFeedBack(
forcePlatform: _forcePlatform,
onTapped: () {},
child: Text(
'Tap me',
style: TextStyle(fontSize: 20),
),
child: Text('Tap me', style: TextStyle(fontSize: 20)),
),
const SizedBox(width: 8),
],
Expand Down Expand Up @@ -160,12 +140,11 @@ class _TouchScreenState extends State<TouchScreen> {
color: counters.entries.first.key,
padding: const EdgeInsets.all(16),
child: _createButtons(
counters.entries.skip(1).toList().asMap().map(
(key, value) => MapEntry(
value.key,
value.value,
),
),
counters.entries
.skip(1)
.toList()
.asMap()
.map((key, value) => MapEntry(value.key, value.value)),
),
),
);
Expand Down
17 changes: 11 additions & 6 deletions example/lib/util/locale/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ class Localization {
static Localization of(BuildContext context) =>
Localizations.of<Localization>(context, Localization)!;

static Future<Localization> load(Locale locale,
{bool showLocalizationKeys = false}) async {
static Future<Localization> load(
Locale locale, {
bool showLocalizationKeys = false,
}) async {
final localizations = Localization();
if (showLocalizationKeys) {
return localizations;
}
final jsonContent = await rootBundle
.loadString('assets/locale/${locale.languageCode}.json');
final jsonContent = await rootBundle.loadString(
'assets/locale/${locale.languageCode}.json',
);
localizations._localisedValues =
json.decode(jsonContent) as Map<String, dynamic>; // ignore: avoid_as
return localizations;
Expand All @@ -33,8 +36,10 @@ class Localization {
if (args == null || args.isEmpty) return value;
var newValue = value;
// ignore: avoid_annotating_with_dynamic
args.asMap().forEach((index, dynamic arg) =>
newValue = _replaceWith(newValue, arg, index + 1));
args.asMap().forEach(
(index, dynamic arg) =>
newValue = _replaceWith(newValue, arg, index + 1),
);
return newValue;
} catch (e) {
return '⚠$key⚠';
Expand Down
14 changes: 6 additions & 8 deletions example/lib/util/locale/localization_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ typedef LocaleFilter = bool Function(String languageCode);
class LocalizationDelegate extends LocalizationsDelegate<Localization> {
static LocaleFilter? localeFilter;
static const defaultLocale = Locale('en');
static const _supportedLanguages = [
'en',
];
static const _supportedLanguages = ['en'];

static const _supportedLocales = [
Locale('en'),
];
static const _supportedLocales = [Locale('en')];

static List<String> get supportedLanguages {
if (localeFilter == null) return _supportedLanguages;
Expand Down Expand Up @@ -52,8 +48,10 @@ class LocalizationDelegate extends LocalizationsDelegate<Localization> {
Future<Localization> load(Locale locale) async {
final newActiveLocale = newLocale ?? locale;
activeLocale = newActiveLocale;
return Localization.load(newActiveLocale,
showLocalizationKeys: showLocalizationKeys);
return Localization.load(
newActiveLocale,
showLocalizationKeys: showLocalizationKeys,
);
}

@override
Expand Down
5 changes: 3 additions & 2 deletions example/lib/viewmodel/stream_test_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:icapps_architecture/icapps_architecture.dart';

class StreamTestViewModel with ChangeNotifierEx {
final _counterStream =
StreamControllerWithInitialValue<int>.broadcast(value: 0);
final _counterStream = StreamControllerWithInitialValue<int>.broadcast(
value: 0,
);
var _current = 0;

int get current => _current;
Expand Down
25 changes: 17 additions & 8 deletions example/lib/widget/provider/provider_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ class ProviderWidget<T extends ChangeNotifier>
required T Function() create,
Widget? child,
Widget Function(
BuildContext context, AppTheme theme, Localization localization)?
childBuilder,
Widget Function(BuildContext context, T viewModel, AppTheme theme,
Localization localization)?
childBuilderWithViewModel,
BuildContext context,
AppTheme theme,
Localization localization,
)? childBuilder,
Widget Function(
BuildContext context,
T viewModel,
AppTheme theme,
Localization localization,
)? childBuilderWithViewModel,
Widget? consumerChild,
Widget Function(BuildContext context, T viewModel, Widget? child)? consumer,
Widget Function(BuildContext context, T viewModel, Widget? child,
AppTheme theme, Localization localization)?
consumerWithThemeAndLocalization,
Widget Function(
BuildContext context,
T viewModel,
Widget? child,
AppTheme theme,
Localization localization,
)? consumerWithThemeAndLocalization,
bool lazy = true,
}) : super(
create: create,
Expand Down
Loading
Loading