State Manager and Generation: Icons, Localization, Bloc for locale, context and assets (svg and icon)
BIN
assets/candy.png
Normal file
After Width: | Height: | Size: 54 KiB |
19
assets/svg/ru.svg
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 -4 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_503_2726)">
|
||||
<rect x="0.25" y="0.25" width="27.5" height="19.5" rx="1.75" fill="white" stroke="#F5F5F5" stroke-width="0.5"/>
|
||||
<mask id="mask0_503_2726" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="28" height="20">
|
||||
<rect x="0.25" y="0.25" width="27.5" height="19.5" rx="1.75" fill="white" stroke="white" stroke-width="0.5"/>
|
||||
</mask>
|
||||
<g mask="url(#mask0_503_2726)">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 13.3333H28V6.66667H0V13.3333Z" fill="#0C47B7"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 20H28V13.3333H0V20Z" fill="#E53B35"/>
|
||||
</g>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_503_2726">
|
||||
<rect width="28" height="20" rx="2" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
After Width: | Height: | Size: 968 B |
23
assets/svg/uk.svg
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 512 512" xml:space="preserve">
|
||||
<path style="fill:#41479B;" d="M473.655,88.276H38.345C17.167,88.276,0,105.443,0,126.621V385.38
|
||||
c0,21.177,17.167,38.345,38.345,38.345h435.31c21.177,0,38.345-17.167,38.345-38.345V126.621
|
||||
C512,105.443,494.833,88.276,473.655,88.276z"/>
|
||||
<path style="fill:#F5F5F5;" d="M511.469,120.282c-3.022-18.159-18.797-32.007-37.814-32.007h-9.977l-163.54,107.147V88.276h-88.276
|
||||
v107.147L48.322,88.276h-9.977c-19.017,0-34.792,13.847-37.814,32.007l139.778,91.58H0v88.276h140.309L0.531,391.717
|
||||
c3.022,18.159,18.797,32.007,37.814,32.007h9.977l163.54-107.147v107.147h88.276V316.577l163.54,107.147h9.977
|
||||
c19.017,0,34.792-13.847,37.814-32.007l-139.778-91.58H512v-88.276H371.691L511.469,120.282z"/>
|
||||
<g>
|
||||
<polygon style="fill:#FF4B55;" points="282.483,88.276 229.517,88.276 229.517,229.517 0,229.517 0,282.483 229.517,282.483
|
||||
229.517,423.724 282.483,423.724 282.483,282.483 512,282.483 512,229.517 282.483,229.517 "/>
|
||||
<path style="fill:#FF4B55;" d="M24.793,421.252l186.583-121.114h-32.428L9.224,410.31
|
||||
C13.377,415.157,18.714,418.955,24.793,421.252z"/>
|
||||
<path style="fill:#FF4B55;" d="M346.388,300.138H313.96l180.716,117.305c5.057-3.321,9.277-7.807,12.287-13.075L346.388,300.138z"
|
||||
/>
|
||||
<path style="fill:#FF4B55;" d="M4.049,109.475l157.73,102.387h32.428L15.475,95.842C10.676,99.414,6.749,104.084,4.049,109.475z"/>
|
||||
<path style="fill:#FF4B55;" d="M332.566,211.862l170.035-110.375c-4.199-4.831-9.578-8.607-15.699-10.86L300.138,211.862H332.566z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.7 KiB |
3
fgen.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
output: lib/components/resources/resources.g.dart
|
||||
watch: false
|
||||
preview: false
|
@ -427,7 +427,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
@ -484,7 +484,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 295 B After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 450 B After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 19 KiB |
6
l10n.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
arb-dir: l10n
|
||||
template-arb-file: app_ru.arb
|
||||
output-localization-file: app_locale.dart
|
||||
output-dir: lib/components/l10n
|
||||
output-class: AppLocale
|
||||
synthetic-package: false
|
12
l10n/app_en.arb
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"@@locale": "en",
|
||||
|
||||
"cardLiked": "Candy added to your favorite :)",
|
||||
"cardDisliked": "Candy deleted form favorite :(",
|
||||
"searchInputPlaceholder": "Search ..",
|
||||
|
||||
"titleCard" : "Title",
|
||||
"descriptionCard" : "Description",
|
||||
"manufacturer" : "Manufacturer",
|
||||
"price": "Price"
|
||||
}
|
12
l10n/app_ru.arb
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"@@locale": "ru",
|
||||
|
||||
"cardLiked": "Сладость добавлена в понравившиеся :)",
|
||||
"cardDisliked": "Сладость удалена из понравившегося :(",
|
||||
"searchInputPlaceholder": "Поиск ..",
|
||||
|
||||
"titleCard" : "Название",
|
||||
"descriptionCard" : "Описание",
|
||||
"manufacturer" : "Производитель",
|
||||
"price" : "Цена"
|
||||
}
|
6
lib/components/extensions/local_context_x.dart
Normal file
@ -0,0 +1,6 @@
|
||||
import 'package:candystore/components/l10n/app_locale.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
extension LocalContextX on BuildContext {
|
||||
AppLocale get locale => AppLocale.of(this)!;
|
||||
}
|
18
lib/presentation/bloc/locale_bloc/locale_bloc.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:candystore/components/l10n/app_locale.dart';
|
||||
import 'package:candystore/presentation/bloc/locale_bloc/locale_event.dart';
|
||||
import 'package:candystore/presentation/bloc/locale_bloc/locale_state.dart';
|
||||
|
||||
class LocaleBloc extends Bloc<LocaleEvent, LocaleState> {
|
||||
LocaleBloc(Locale defaultLocale) : super(LocaleState(currentLocale: defaultLocale)) {
|
||||
on<ChangeLocaleEvent>(_onChangeLocale);
|
||||
}
|
||||
|
||||
Future<void> _onChangeLocale(ChangeLocaleEvent event, Emitter<LocaleState> emit) async {
|
||||
final toChange = AppLocale.supportedLocales
|
||||
.firstWhere((e) => e.languageCode != state.currentLocale.languageCode);
|
||||
|
||||
emit(state.copyWith(currentLocale: toChange));
|
||||
}
|
||||
}
|
7
lib/presentation/bloc/locale_bloc/locale_event.dart
Normal file
@ -0,0 +1,7 @@
|
||||
abstract class LocaleEvent {
|
||||
const LocaleEvent();
|
||||
}
|
||||
|
||||
class ChangeLocaleEvent extends LocaleEvent {
|
||||
const ChangeLocaleEvent();
|
||||
}
|
15
lib/presentation/bloc/locale_bloc/locale_state.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
part 'locale_state.g.dart';
|
||||
|
||||
@CopyWith()
|
||||
class LocaleState extends Equatable {
|
||||
final Locale currentLocale;
|
||||
|
||||
const LocaleState({required this.currentLocale});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [currentLocale];
|
||||
}
|
35
lib/presentation/common/svg_objects.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:candystore/components/resources/resources.g.dart';
|
||||
|
||||
abstract class SvgObjects {
|
||||
static void init() {
|
||||
final pics = <String>[
|
||||
R.ASSETS_SVG_RU_SVG,
|
||||
R.ASSETS_SVG_UK_SVG,
|
||||
];
|
||||
|
||||
for (final String p in pics) {
|
||||
final loader = SvgAssetLoader(p);
|
||||
svg.cache.putIfAbsent(loader.cacheKey(null), () => loader.loadBytes(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SvgRu extends StatelessWidget {
|
||||
const SvgRu({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SvgPicture.asset(R.ASSETS_SVG_RU_SVG);
|
||||
}
|
||||
}
|
||||
|
||||
class SvgUk extends StatelessWidget {
|
||||
const SvgUk({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SvgPicture.asset(R.ASSETS_SVG_UK_SVG);
|
||||
}
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import shared_preferences_foundation
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
}
|
||||
|
25
makefile
Normal file
@ -0,0 +1,25 @@
|
||||
gen:
|
||||
flutter pub run build_runner build --delete-conflicting-outputs
|
||||
|
||||
hello:
|
||||
echo "Hello, user"; \
|
||||
echo "uraaa, makefile working"; \
|
||||
echo "^_^"
|
||||
|
||||
icon:
|
||||
flutter pub run flutter_launcher_icons:main
|
||||
|
||||
init_res:
|
||||
dart pub global activate flutter_asset_generator
|
||||
|
||||
format:
|
||||
dart format . --line-length 100
|
||||
|
||||
res:
|
||||
dart pub global activate fgen
|
||||
fgen --outputs lib/components/resources.g.dart --no-watch --no-preview; \
|
||||
make format
|
||||
|
||||
loc:
|
||||
flutter gen-l10n; \
|
||||
make format
|