mirror of
https://github.com/smmarty/friflex_flutter_starter.git
synced 2025-12-22 01:20:46 +00:00
feat(app): Добавить fluttergen (#3)
Co-authored-by: PetrovY <y.petrov@friflex.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:friflex_starter/app/app_context_ext.dart';
|
||||
import 'package:friflex_starter/app/theme/app_theme.dart';
|
||||
import 'package:friflex_starter/app/theme/theme_notifier.dart';
|
||||
import 'package:friflex_starter/di/di_container.dart';
|
||||
import 'package:friflex_starter/l10n/gen/app_localizations.dart';
|
||||
import 'package:friflex_starter/l10n/localization_notifier.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:friflex_starter/app/theme/theme_notifier.dart';
|
||||
import 'package:friflex_starter/di/di_container.dart';
|
||||
import 'package:friflex_starter/l10n/gen/app_localizations.dart';
|
||||
import 'package:friflex_starter/l10n/localization_notifier.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ import 'package:i_app_services/i_app_services.dart';
|
||||
/// {@endtemplate}
|
||||
final class DiContainer {
|
||||
/// {@macro dependencies_container}
|
||||
DiContainer({required this.env, required IDebugService dService}) : debugService = dService;
|
||||
DiContainer({required this.env, required IDebugService dService})
|
||||
: debugService = dService;
|
||||
final AppEnv env;
|
||||
|
||||
/// Сервис для отладки, получаем из конструктора
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/app_context_ext.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
import 'package:friflex_starter/gen/assets.gen.dart';
|
||||
import 'package:friflex_starter/gen/fonts.gen.dart';
|
||||
|
||||
class DebugScreen extends StatelessWidget {
|
||||
const DebugScreen({Key? key}) : super(key: key);
|
||||
@@ -9,30 +12,77 @@ class DebugScreen extends StatelessWidget {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Debug Screen')),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Text(
|
||||
'Реализация SecureStorage: ${context.di.secureStorage.nameImpl}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Окружение: ${context.di.appConfig.env.name}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
throw Exception(
|
||||
'Тестовая ошибка Exception для отладки FlutterError',);
|
||||
context.theme.changeTheme();
|
||||
},
|
||||
child: const Text('Вызывать ошибку FlutterError'),
|
||||
child: const Text('Сменить тему'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ColoredBox(
|
||||
color: context.colors.testColor,
|
||||
child: const SizedBox(height: 100, width: 100),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Текущая тема: ${context.theme.themeMode}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Текущий репозиторий: ${context.di.repositories.authRepository.name}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await callError();
|
||||
onPressed: () {
|
||||
context.localization.changeLocal(
|
||||
const Locale('ru', 'RU'),
|
||||
);
|
||||
},
|
||||
child: const Text('Вызывать ошибку PlatformDispatcher'),
|
||||
child: const Text('Сменить язык на Rусский'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await context.di.debugService.openDebugScreen(context);
|
||||
onPressed: () {
|
||||
context.localization.changeLocal(
|
||||
const Locale('en', 'EN'),
|
||||
);
|
||||
},
|
||||
child: const Text('Вызывать Экран отладки'),
|
||||
child: const Text('Сменить язык на Английский'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Тестовое слово montserrat bold: ${context.l10n.helloWorld}',
|
||||
style: TextStyle(
|
||||
color: context.colors.testColor,
|
||||
fontFamily: Assets.fonts.montserratBold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Тестовое слово montserrat medium: ${context.l10n.helloWorld}',
|
||||
style: TextStyle(
|
||||
color: context.colors.testColor,
|
||||
fontFamily: FontFamily.montserrat,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Текущий язык: ${context.l10n.localeName}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Тестовая иконка из assets'),
|
||||
Assets.icons.home.svg(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/app_context_ext.dart';
|
||||
import 'package:friflex_starter/app/theme/app_colors_scheme.dart';
|
||||
|
||||
class MainScreen extends StatelessWidget {
|
||||
const MainScreen({super.key});
|
||||
@@ -10,67 +8,7 @@ class MainScreen extends StatelessWidget {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Main Screen'),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'Реализация SecureStorage: ${context.di.secureStorage.nameImpl}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Окружение: ${context.di.appConfig.env.name}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.theme.changeTheme();
|
||||
},
|
||||
child: const Text('Сменить тему'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ColoredBox(
|
||||
color: context.colors.testColor,
|
||||
child: const SizedBox(height: 100, width: 100),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Текущая тема: ${context.theme.themeMode}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Текущий репозиторий: ${context.di.repositories.authRepository.name}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.localization.changeLocal(
|
||||
const Locale('ru', 'RU'),
|
||||
);
|
||||
},
|
||||
child: const Text('Сменить язык на Rусский'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.localization.changeLocal(
|
||||
const Locale('en', 'EN'),
|
||||
);
|
||||
},
|
||||
child: const Text('Сменить язык на Английский'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Тестовое слово: ${context.l10n.helloWorld}',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Текущий язык: ${context.l10n.localeName}',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
135
lib/gen/assets.gen.dart
Normal file
135
lib/gen/assets.gen.dart
Normal file
@@ -0,0 +1,135 @@
|
||||
/// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
/// *****************************************************
|
||||
/// FlutterGen
|
||||
/// *****************************************************
|
||||
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart' as _svg;
|
||||
import 'package:vector_graphics/vector_graphics.dart' as _vg;
|
||||
|
||||
class $AssetsFontsGen {
|
||||
const $AssetsFontsGen();
|
||||
|
||||
/// File path: assets/fonts/Montserrat-Bold.ttf
|
||||
String get montserratBold => 'assets/fonts/Montserrat-Bold.ttf';
|
||||
|
||||
/// File path: assets/fonts/Montserrat-ExtraBold.ttf
|
||||
String get montserratExtraBold => 'assets/fonts/Montserrat-ExtraBold.ttf';
|
||||
|
||||
/// File path: assets/fonts/Montserrat-Medium.ttf
|
||||
String get montserratMedium => 'assets/fonts/Montserrat-Medium.ttf';
|
||||
|
||||
/// File path: assets/fonts/Montserrat-Regular.ttf
|
||||
String get montserratRegular => 'assets/fonts/Montserrat-Regular.ttf';
|
||||
|
||||
/// File path: assets/fonts/Montserrat-SemiBold.ttf
|
||||
String get montserratSemiBold => 'assets/fonts/Montserrat-SemiBold.ttf';
|
||||
|
||||
/// List of all assets
|
||||
List<String> get values => [
|
||||
montserratBold,
|
||||
montserratExtraBold,
|
||||
montserratMedium,
|
||||
montserratRegular,
|
||||
montserratSemiBold
|
||||
];
|
||||
}
|
||||
|
||||
class $AssetsIconsGen {
|
||||
const $AssetsIconsGen();
|
||||
|
||||
/// File path: assets/icons/home.svg
|
||||
SvgGenImage get home => const SvgGenImage('assets/icons/home.svg');
|
||||
|
||||
/// List of all assets
|
||||
List<SvgGenImage> get values => [home];
|
||||
}
|
||||
|
||||
class Assets {
|
||||
Assets._();
|
||||
|
||||
static const $AssetsFontsGen fonts = $AssetsFontsGen();
|
||||
static const $AssetsIconsGen icons = $AssetsIconsGen();
|
||||
}
|
||||
|
||||
class SvgGenImage {
|
||||
const SvgGenImage(
|
||||
this._assetName, {
|
||||
this.size,
|
||||
this.flavors = const {},
|
||||
}) : _isVecFormat = false;
|
||||
|
||||
const SvgGenImage.vec(
|
||||
this._assetName, {
|
||||
this.size,
|
||||
this.flavors = const {},
|
||||
}) : _isVecFormat = true;
|
||||
|
||||
final String _assetName;
|
||||
final Size? size;
|
||||
final Set<String> flavors;
|
||||
final bool _isVecFormat;
|
||||
|
||||
_svg.SvgPicture svg({
|
||||
Key? key,
|
||||
bool matchTextDirection = false,
|
||||
AssetBundle? bundle,
|
||||
String? package,
|
||||
double? width,
|
||||
double? height,
|
||||
BoxFit fit = BoxFit.contain,
|
||||
AlignmentGeometry alignment = Alignment.center,
|
||||
bool allowDrawingOutsideViewBox = false,
|
||||
WidgetBuilder? placeholderBuilder,
|
||||
String? semanticsLabel,
|
||||
bool excludeFromSemantics = false,
|
||||
_svg.SvgTheme? theme,
|
||||
ColorFilter? colorFilter,
|
||||
Clip clipBehavior = Clip.hardEdge,
|
||||
@deprecated Color? color,
|
||||
@deprecated BlendMode colorBlendMode = BlendMode.srcIn,
|
||||
@deprecated bool cacheColorFilter = false,
|
||||
}) {
|
||||
final _svg.BytesLoader loader;
|
||||
if (_isVecFormat) {
|
||||
loader = _vg.AssetBytesLoader(
|
||||
_assetName,
|
||||
assetBundle: bundle,
|
||||
packageName: package,
|
||||
);
|
||||
} else {
|
||||
loader = _svg.SvgAssetLoader(
|
||||
_assetName,
|
||||
assetBundle: bundle,
|
||||
packageName: package,
|
||||
theme: theme,
|
||||
);
|
||||
}
|
||||
return _svg.SvgPicture(
|
||||
loader,
|
||||
key: key,
|
||||
matchTextDirection: matchTextDirection,
|
||||
width: width,
|
||||
height: height,
|
||||
fit: fit,
|
||||
alignment: alignment,
|
||||
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
|
||||
placeholderBuilder: placeholderBuilder,
|
||||
semanticsLabel: semanticsLabel,
|
||||
excludeFromSemantics: excludeFromSemantics,
|
||||
colorFilter: colorFilter ??
|
||||
(color == null ? null : ColorFilter.mode(color, colorBlendMode)),
|
||||
clipBehavior: clipBehavior,
|
||||
cacheColorFilter: cacheColorFilter,
|
||||
);
|
||||
}
|
||||
|
||||
String get path => _assetName;
|
||||
|
||||
String get keyName => _assetName;
|
||||
}
|
||||
15
lib/gen/fonts.gen.dart
Normal file
15
lib/gen/fonts.gen.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
/// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
/// *****************************************************
|
||||
/// FlutterGen
|
||||
/// *****************************************************
|
||||
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
|
||||
|
||||
class FontFamily {
|
||||
FontFamily._();
|
||||
|
||||
/// Font family: Montserrat
|
||||
static const String montserrat = 'Montserrat';
|
||||
}
|
||||
135
lib/l10n/gen/app_localizations.dart
Normal file
135
lib/l10n/gen/app_localizations.dart
Normal file
@@ -0,0 +1,135 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
import 'app_localizations_en.dart';
|
||||
import 'app_localizations_ru.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
/// Callers can lookup localized strings with an instance of AppLocalizations
|
||||
/// returned by `AppLocalizations.of(context)`.
|
||||
///
|
||||
/// Applications need to include `AppLocalizations.delegate()` in their app's
|
||||
/// `localizationDelegates` list, and the locales they support in the app's
|
||||
/// `supportedLocales` list. For example:
|
||||
///
|
||||
/// ```dart
|
||||
/// import 'gen/app_localizations.dart';
|
||||
///
|
||||
/// return MaterialApp(
|
||||
/// localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
/// supportedLocales: AppLocalizations.supportedLocales,
|
||||
/// home: MyApplicationHome(),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// ## Update pubspec.yaml
|
||||
///
|
||||
/// Please make sure to update your pubspec.yaml to include the following
|
||||
/// packages:
|
||||
///
|
||||
/// ```yaml
|
||||
/// dependencies:
|
||||
/// # Internationalization support.
|
||||
/// flutter_localizations:
|
||||
/// sdk: flutter
|
||||
/// intl: any # Use the pinned version from flutter_localizations
|
||||
///
|
||||
/// # Rest of dependencies
|
||||
/// ```
|
||||
///
|
||||
/// ## iOS Applications
|
||||
///
|
||||
/// iOS applications define key application metadata, including supported
|
||||
/// locales, in an Info.plist file that is built into the application bundle.
|
||||
/// To configure the locales supported by your app, you’ll need to edit this
|
||||
/// file.
|
||||
///
|
||||
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
|
||||
/// Then, in the Project Navigator, open the Info.plist file under the Runner
|
||||
/// project’s Runner folder.
|
||||
///
|
||||
/// Next, select the Information Property List item, select Add Item from the
|
||||
/// Editor menu, then select Localizations from the pop-up menu.
|
||||
///
|
||||
/// Select and expand the newly-created Localizations item then, for each
|
||||
/// locale your application supports, add a new item and select the locale
|
||||
/// you wish to add from the pop-up menu in the Value field. This list should
|
||||
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
|
||||
/// property.
|
||||
abstract class AppLocalizations {
|
||||
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||||
|
||||
final String localeName;
|
||||
|
||||
static AppLocalizations? of(BuildContext context) {
|
||||
return Localizations.of<AppLocalizations>(context, AppLocalizations);
|
||||
}
|
||||
|
||||
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate();
|
||||
|
||||
/// A list of this localizations delegate along with the default localizations
|
||||
/// delegates.
|
||||
///
|
||||
/// Returns a list of localizations delegates containing this delegate along with
|
||||
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
|
||||
/// and GlobalWidgetsLocalizations.delegate.
|
||||
///
|
||||
/// Additional delegates can be added by appending to this list in
|
||||
/// MaterialApp. This list does not have to be used at all if a custom list
|
||||
/// of delegates is preferred or required.
|
||||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
|
||||
delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
];
|
||||
|
||||
/// A list of this localizations delegate's supported locales.
|
||||
static const List<Locale> supportedLocales = <Locale>[
|
||||
Locale('en'),
|
||||
Locale('ru')
|
||||
];
|
||||
|
||||
/// The conventional newborn programmer greeting
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Hello World!'**
|
||||
String get helloWorld;
|
||||
}
|
||||
|
||||
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||
const _AppLocalizationsDelegate();
|
||||
|
||||
@override
|
||||
Future<AppLocalizations> load(Locale locale) {
|
||||
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSupported(Locale locale) => <String>['en', 'ru'].contains(locale.languageCode);
|
||||
|
||||
@override
|
||||
bool shouldReload(_AppLocalizationsDelegate old) => false;
|
||||
}
|
||||
|
||||
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||||
|
||||
|
||||
// Lookup logic when only language code is specified.
|
||||
switch (locale.languageCode) {
|
||||
case 'en': return AppLocalizationsEn();
|
||||
case 'ru': return AppLocalizationsRu();
|
||||
}
|
||||
|
||||
throw FlutterError(
|
||||
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
|
||||
'an issue with the localizations generation tool. Please file an issue '
|
||||
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||||
'that was used.'
|
||||
);
|
||||
}
|
||||
11
lib/l10n/gen/app_localizations_en.dart
Normal file
11
lib/l10n/gen/app_localizations_en.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'app_localizations.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
/// The translations for English (`en`).
|
||||
class AppLocalizationsEn extends AppLocalizations {
|
||||
AppLocalizationsEn([String locale = 'en']) : super(locale);
|
||||
|
||||
@override
|
||||
String get helloWorld => 'Hello World!';
|
||||
}
|
||||
11
lib/l10n/gen/app_localizations_ru.dart
Normal file
11
lib/l10n/gen/app_localizations_ru.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'app_localizations.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
/// The translations for Russian (`ru`).
|
||||
class AppLocalizationsRu extends AppLocalizations {
|
||||
AppLocalizationsRu([String locale = 'ru']) : super(locale);
|
||||
|
||||
@override
|
||||
String get helloWorld => 'Привет, мир!';
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class AppRouter {
|
||||
static final rootNavigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
/// Начальный роут приложения
|
||||
static String get initialLocation => '/main';
|
||||
static String get initialLocation => '/debug';
|
||||
|
||||
/// Метод для создания экземпляра GoRouter
|
||||
static GoRouter createRouter(IDebugService debugService) {
|
||||
|
||||
Reference in New Issue
Block a user