Начальный коммит

This commit is contained in:
2026-01-30 21:54:00 +07:00
parent 51de113db5
commit 3881248187
81 changed files with 5424 additions and 0 deletions

19
.idea/libraries/Dart_SDK.xml generated Normal file
View File

@@ -0,0 +1,19 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/async" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/collection" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/convert" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/core" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/developer" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/html" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/io" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/isolate" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/math" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/mirrors" />
<root url="file://D:\sdk\flutter/bin/cache/dart-sdk/lib/typed_data" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

15
.idea/libraries/KotlinJavaRuntime.xml generated Normal file
View File

@@ -0,0 +1,15 @@
<component name="libraryTable">
<library name="KotlinJavaRuntime">
<CLASSES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test-sources.jar!/" />
</SOURCES>
</library>
</component>

9
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/flutter_stocky.iml" filepath="$PROJECT_DIR$/flutter_stocky.iml" />
<module fileurl="file://$PROJECT_DIR$/android/flutter_stocky_android.iml" filepath="$PROJECT_DIR$/android/flutter_stocky_android.iml" />
</modules>
</component>
</project>

6
.idea/runConfigurations/main_dart.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

36
.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="ToolWindowManager">
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
</layout>
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
</navigator>
<panes>
<pane id="ProjectPane">
<option name="show-excluded-files" value="false" />
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="dart.analysis.tool.window.force.activate" value="true" />
<property name="show.migrate.to.gradle.popup" value="false" />
</component>
</project>

30
.metadata Normal file
View File

@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: "fcf2c11572af6f390246c056bc905eca609533a0"
channel: "stable"
project_type: app
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: fcf2c11572af6f390246c056bc905eca609533a0
base_revision: fcf2c11572af6f390246c056bc905eca609533a0
- platform: web
create_revision: fcf2c11572af6f390246c056bc905eca609533a0
base_revision: fcf2c11572af6f390246c056bc905eca609533a0
# User provided section
# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'

24
.vscode/Region.code-snippets vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"Region: Проверено": {
"prefix": "region-done",
"body": [
"// region 🟢 Проверено: $1",
"",
"$2",
"",
"// endregion"
],
"description": "Сворачиваемый блок: проверено"
},
"Region: Не проверено": {
"prefix": "region-pending",
"body": [
"// region 🔴 Не проверено: $1",
"",
"$2",
"",
"// endregion"
],
"description": "Сворачиваемый блок: не проверено"
}
}

7
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"files.associations": {
"*.ejs": "html",
"vector": "cpp"
},
"java.configuration.updateBuildConfiguration": "interactive"
}

1
analysis_options.yaml Normal file
View File

@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml

14
android/.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
.cxx/
# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
key.properties
**/*.keystore
**/*.jks

View File

@@ -0,0 +1,53 @@
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
id("com.google.gms.google-services")
}
dependencies {
implementation(platform("com.google.firebase:firebase-bom:34.8.0"))
implementation("com.google.firebase:firebase-auth")
implementation("com.google.firebase:firebase-firestore")
implementation("com.google.firebase:firebase-analytics") // опционально
}
android {
namespace = "com.autoritet.stocky"
compileSdk = flutter.compileSdkVersion
ndkVersion = "27.0.12077973"
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.autoritet.stocky"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = 23
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}
flutter {
source = "../.."
}

View File

@@ -0,0 +1,86 @@
{
"project_info": {
"project_number": "785043562091",
"project_id": "apllicationswork",
"storage_bucket": "apllicationswork.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:785043562091:android:359470686cf07bd27c5b2e",
"android_client_info": {
"package_name": "com.autorite.service"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBGgbGEs6fe9jJgyIWjsRaCmrifC4pjxQo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:785043562091:android:acd0ecee72a5c6967c5b2e",
"android_client_info": {
"package_name": "com.autoritet.mechanic"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBGgbGEs6fe9jJgyIWjsRaCmrifC4pjxQo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:785043562091:android:abc115731c662f297c5b2e",
"android_client_info": {
"package_name": "com.autoritet.stocky"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBGgbGEs6fe9jJgyIWjsRaCmrifC4pjxQo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:785043562091:android:e49461a9466508b77c5b2e",
"android_client_info": {
"package_name": "com.example.receiver"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBGgbGEs6fe9jJgyIWjsRaCmrifC4pjxQo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}

View File

@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@@ -0,0 +1,45 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="Stocky"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>

View File

@@ -0,0 +1,5 @@
package com.autoritet.stocky
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity()

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

View File

@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

21
android/build.gradle.kts Normal file
View File

@@ -0,0 +1,21 @@
allprojects {
repositories {
google()
mavenCentral()
}
}
val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)
subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/app/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/app/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/app/src/main/assets" />
<option name="LIBS_FOLDER_RELATIVE_PATH" value="/app/src/main/libs" />
<option name="PROGUARD_LOGS_FOLDER_RELATIVE_PATH" value="/app/src/main/proguard_logs" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/app/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Flutter for Android" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>

View File

@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true

View File

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip

View File

@@ -0,0 +1,28 @@
pluginManagement {
val flutterSdkPath = run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
flutterSdkPath
}
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.7.3" apply false
// START: FlutterFire Configuration
id("com.google.gms.google-services") version("4.3.15") apply false
// END: FlutterFire Configuration
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
}
include(":app")

3
devtools_options.yaml Normal file
View File

@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:

1
firebase.json Normal file
View File

@@ -0,0 +1 @@
{"flutter":{"platforms":{"android":{"default":{"projectId":"apllicationswork","appId":"1:785043562091:android:abc115731c662f297c5b2e","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"apllicationswork","configurations":{"android":"1:785043562091:android:abc115731c662f297c5b2e","web":"1:785043562091:web:bae3c514d31ac7ce7c5b2e","windows":"1:785043562091:web:6f0beb2b421d6ba27c5b2e"}}}}}}

17
flutter_stocky.iml Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View File

@@ -0,0 +1,75 @@
// lib/controllers/auth_controller.dart
import 'package:Stocky/services/api/api_service.dart';
import 'package:Stocky/services/local/StorageService.dart';
import 'package:get/get.dart';
class AuthController extends GetxController {
// Состояния
final _state = 'inputPhone'.obs;
final ApiService apicontr = Get.find<ApiService>();
Rx<String> phoneNumber = ''.obs;
Rx<String> verificationCode = ''.obs;
// Получаем текущее состояние
String get state => _state.value;
// Меняем состояние
void setState(String newState) {
_state.value = newState;
}
// Ввод номера
void phoneNumberInput(String value) {
phoneNumber.value = value;
}
// Проверка номера
bool get isPhoneNumberValid {
final clean = phoneNumber.value.replaceAll(RegExp(r'[^0-9]'), '');
return clean.length == 11 && clean.startsWith('7'); // или 10, если без +7
}
// Получить "чистый" номер (для отправки на сервер)
String get phoneNumberClean {
return phoneNumber.value.replaceAll(RegExp(r'[^0-9]'), '');
}
// Ввод кода
void verificationCodeInput(String value) {
verificationCode.value = value;
}
Future<void> sendCode() async {
if (phoneNumber.value.isEmpty) {
Get.snackbar('Ошибка', 'Введите номер телефона');
return;
}
if (!isPhoneNumberValid) {
Get.snackbar('Ошибка', 'Неверный номер телефона');
return;
}
await Future.delayed(const Duration(seconds: 1));
setState('inputCode');
await apicontr.registerByPhone(phoneNumberClean);
}
// Подтвердить код
Future<void> submit() async {
if (verificationCode.value.isEmpty) {
Get.snackbar('Ошибка', 'Введите код подтверждения');
return;
}
await Future.delayed(const Duration(seconds: 1));
final reg = await apicontr.loginByPhone(
phoneNumber.value,
verificationCode.value,
);
if (reg) {
Get.find<LocalStorageService>().putNumber(phoneNumber.value);
Get.snackbar('Успешно', 'Вы вошли!');
Get.offAllNamed('/home');
}
}
}

View File

@@ -0,0 +1,233 @@
import 'package:Stocky/models/task_adapter.dart';
import 'package:Stocky/models/Documents.dart';
import 'package:Stocky/services/api/api_service.dart';
import 'package:Stocky/services/api/push_notification_service.dart';
import 'package:Stocky/services/local/StorageService.dart';
import 'package:get/get.dart';
class MainController extends GetxController {
final username = ''.obs;
final tasks = <Task>[].obs;
final documents = <Document>[].obs;
final RxBool isLoading = false.obs;
final RxBool isTask = true.obs;
final RxBool isProj = true.obs;
bool _isSyncingTasks = false;
Future<void> getSettings() async {
username.value = await Get.find<LocalStorageService>().getUsername();
}
Future<void> fetchTasks() async {
if (_isSyncingTasks) return;
_isSyncingTasks = true;
try {
isLoading.value = true;
final localTasks = Get.find<LocalStorageService>().getTasks();
if (localTasks.isEmpty) {
await _fetchTasksFromServer();
} else {
await _syncTasksWithServer(localTasks);
}
final activeTasks = await Get.find<LocalStorageService>()
.getCompletedTasks();
tasks.assignAll(activeTasks);
} catch (e) {
print('Ошибка при синхронизации задач: $e');
} finally {
_isSyncingTasks = false;
isLoading.value = false;
}
}
Future<void> _syncTasksWithServer(List<Task> localTasks) async {
try {
// Шаг 1: Обрабатываем все несинхронизированные задачи
final unsyncedTasks = localTasks.where((t) => !t.isSynced).toList();
for (final task in unsyncedTasks) {
if (task.isDeletedLocally == true) {
// Удаление: пытаемся удалить на сервере
final deleted = await Get.find<ApiService>().deleteTask(
task.id.toString(),
);
if (deleted) {
Get.find<LocalStorageService>().removeTask(task.id);
} else {
// Не удалось — оставляем помеченной, попробуем позже
continue;
}
} else {
// Создание или обновление
final syncedTask = await Get.find<ApiService>().upsertTask(task);
if (syncedTask != null) {
syncedTask.isSynced = true;
syncedTask.isDeletedLocally = false;
Get.find<LocalStorageService>().updateTask(syncedTask);
}
// Если не удалось — остаётся с isSynced = false
}
}
// Шаг 2: Получаем актуальный список с сервера
final serverTasks = await Get.find<ApiService>().fetchTasks();
await Get.find<LocalStorageService>().saveTasks(serverTasks);
} catch (e) {
print('Ошибка синхронизации: $e');
// В случае ошибки — восстанавливаем локальный список
tasks.assignAll(localTasks);
}
}
Future<void> _fetchTasksFromServer() async {
try {
final serverTasks = await Get.find<ApiService>().fetchTasks();
await Get.find<LocalStorageService>().saveTasks(serverTasks);
tasks.assignAll(serverTasks);
} catch (e) {
print('Ошибка загрузки задач с сервера: $e');
// Остаёмся с пустым списком
}
}
Future<void> assignTaskToCurrentUser(Task task) async {
task.executor = username.value;
task.isSynced = false;
updateTask(task);
}
Future<void> completeTask(Task task) async {
task.isCompleted = true;
task.endTime = DateTime.now();
task.isSynced = false;
updateTask(task);
final activeTasks = await Get.find<LocalStorageService>()
.getCompletedTasks();
tasks.assignAll(activeTasks);
}
Future<void> addTask(Task task) async {
task.isSynced = false;
task.isDeletedLocally = false;
Get.find<LocalStorageService>().addTask(task);
tasks.add(task);
_syncTaskToServer(task);
}
Future<void> updateTask(Task updatedTask) async {
final index = tasks.indexWhere((t) => t.id == updatedTask.id);
if (index == -1) return;
updatedTask.isSynced = false;
updatedTask.isDeletedLocally = false;
Get.find<LocalStorageService>().updateTask(updatedTask);
tasks[index] = updatedTask;
_syncTaskToServer(updatedTask);
}
Future<void> deleteTask(Task task) async {
final index = tasks.indexWhere((t) => t.id == task.id);
if (index == -1) return;
try {
final success = await Get.find<ApiService>().deleteTask(
task.id.toString(),
);
if (success) {
Get.find<LocalStorageService>().removeTask(task.id);
tasks.removeAt(index);
} else {
// Нет связи — помечаем для отложенного удаления
_markTaskForDeletion(task);
}
} catch (e) {
print('Ошибка при удалении задачи: $e');
_markTaskForDeletion(task);
}
}
void _markTaskForDeletion(Task task) {
task.isDeletedLocally = true;
task.isSynced = false;
Get.find<LocalStorageService>().updateTask(task);
}
Future<void> _syncTaskToServer(Task task) async {
final storage = Get.find<LocalStorageService>();
if (task.isDeletedLocally == true) {
final success = await Get.find<ApiService>().deleteTask(
task.id.toString(),
);
if (success) {
storage.removeTask(task.id);
tasks.removeWhere((t) => t.id == task.id);
} else {
// Оставить помеченной — будет обработано при полной синхронизации
}
return;
}
try {
final syncedTask = await Get.find<ApiService>().upsertTask(task);
if (syncedTask == null) return;
if (syncedTask.id != task.id) {
syncedTask.isSynced = true;
syncedTask.isDeletedLocally = false;
await storage.replaceTask(task.id, syncedTask);
} else {
task.isSynced = true;
task.isDeletedLocally = false;
await storage.updateTask(syncedTask);
}
final index = tasks.indexWhere((t) => t.id == task.id);
if (index != -1) {
if (syncedTask.id != task.id) {
tasks.removeAt(index);
tasks.add(syncedTask);
} else {
tasks[index] = syncedTask;
}
}
} catch (e) {
print('Ошибка синхронизации: $e');
}
}
Task? openTask(String taskId) {
return tasks.firstWhereOrNull((task) => task.id == taskId);
}
@override
void onInit() async {
super.onInit();
Get.find<PushNotificationService>().foregroundMessageStream.listen((
message,
) {
// _handleMessageAction(message); // тот же метод, что и выше
});
getSettings();
fetchTasks();
}
void openTaskFromNotification(String taskId) {
Get.toNamed('/task', arguments: {'id': taskId});
}
}

View File

@@ -0,0 +1,32 @@
import 'package:Stocky/services/local/StorageService.dart';
import 'package:get/get.dart';
class SplashScreenController extends GetxController {
late Future<bool> _authCheck;
@override
void onInit() {
super.onInit();
_authCheck = _checkAuthentication();
}
Future<bool> _checkAuthentication() async {
final LocalStorageService settings = Get.find<LocalStorageService>();
final accessToken = settings.getAccessToken();
if (accessToken != null && accessToken.isNotEmpty) {
return true;
}
return false;
}
Future<void> navigateBasedOnAuth() async {
final isAuthenticated = await _authCheck;
if (isAuthenticated) {
Get.offAllNamed('/home');
} else {
Get.offAllNamed('/login');
}
}
}

View File

@@ -0,0 +1,148 @@
// lib/pages/login_screen.dart
import 'package:flutter/material.dart';
import 'package:Stocky/Pages/controllers/AuthController.dart';
import 'package:Stocky/Pages/widgets/phone_input_formatter.dart';
import 'package:Stocky/classes/styles.dart';
import 'package:get/get.dart';
import 'package:extended_masked_text/extended_masked_text.dart';
class LoginScreen extends StatelessWidget {
final AuthController controller = Get.put(AuthController());
LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Вход", style: AppStyles.titleLarge)),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Добро пожаловать!",
style: AppStyles.titleLarge, // ← Стиль заголовка
textAlign: TextAlign.center,
),
const SizedBox(height: 30),
Obx(() => _buildAuthForm(controller)),
const SizedBox(height: 40),
Text(
"Мы отправим SMS для подтверждения",
style: AppStyles.description, // ← Стиль описания
textAlign: TextAlign.center,
),
],
),
),
);
}
Widget _buildAuthForm(AuthController controller) {
if (controller.state == 'inputPhone') {
return _buildPhoneInputForm(controller);
} else {
return _buildCodeInputForm(controller);
}
}
Widget _buildPhoneInputForm(AuthController controller) {
final phonecontrol = MaskedTextController(mask: '+7 (000) 000-00-00');
return Column(
children: [
// Ввод номера
TextField(
controller: phonecontrol,
onChanged: controller.phoneNumberInput,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: "Номер телефона",
prefixIcon: AppStyles.createPrimaryIcon(Icons.phone),
hintText: "+7 (999) 123-45-67",
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
filled: true,
fillColor: Colors.grey[100],
labelStyle: AppStyles.body, // ← Стиль для метки
hintStyle: AppStyles.description, // ← Стиль для подсказки
),
inputFormatters: [PhoneInputFormatter()],
),
const SizedBox(height: 30),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: controller.sendCode,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
"Отправить код",
style: AppStyles.title, // ← Стиль текста кнопки
),
),
),
],
);
}
Widget _buildCodeInputForm(AuthController controller) {
return Column(
children: [
// Ввод кода
TextField(
controller: MaskedTextController(mask: '00000'),
onChanged: controller.verificationCodeInput,
keyboardType: TextInputType.number,
obscureText: true,
decoration: InputDecoration(
labelText: "Код подтверждения",
prefixIcon: AppStyles.createPrimaryIcon(Icons.lock),
hintText: "Введите 6-значный код",
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
filled: true,
fillColor: Colors.grey[100],
labelStyle: AppStyles.body,
hintStyle: AppStyles.description,
),
),
const SizedBox(height: 30),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: controller.submit,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text("Подтвердить", style: AppStyles.title),
),
),
// Кнопка "Назад"
const SizedBox(height: 20),
TextButton(
onPressed: () {
controller.setState('inputPhone');
controller.verificationCode('');
},
child: Text(
"Вернуться к вводу номера",
style: AppStyles.link, // ← Стиль ссылки
),
),
],
);
}
}

View File

@@ -0,0 +1,596 @@
import 'package:flutter/material.dart';
import 'package:Stocky/Pages/controllers/MainController.dart';
import 'package:Stocky/Pages/views/tasks_screen.dart';
import 'package:Stocky/classes/styles.dart';
import 'package:Stocky/models/task_adapter.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter_advanced_avatar/flutter_advanced_avatar.dart';
import 'package:get/get.dart';
class HomeScreen extends GetWidget<MainController> {
HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.backgroundColor,
appBar: _buildAppBar(context),
drawer: _buildDrawer(context),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: _buildFilterChips(context),
),
Obx(
() => controller.isProj.value
? SizedBox(
height: 220,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: _buildScrollableSection(
context,
child: _buildProjectsSection(context),
),
),
)
: SizedBox(),
),
// Задачи / Процессы
Padding(
padding: const EdgeInsets.all(8.0),
child: Obx(
() => controller.isTask.value
? _buildProcessSection(context)
: SizedBox(),
),
),
],
),
),
);
}
Widget _buildScrollableSection(
BuildContext context, {
required Widget child,
}) {
return LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(child: child);
},
);
}
AppBar _buildAppBar(BuildContext context) {
return AppBar(
title: const Text('Рабочая область'),
backgroundColor: AppColors.backgroundColor,
actions: [
IconButton(
icon: Icon(
EvaIcons.bellOutline,
size: 26,
color: Colors.blueGrey[700],
),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Оповещения'),
backgroundColor: Colors.blueAccent,
),
);
},
),
],
);
}
Widget _buildFilterChips(BuildContext context) {
return Row(
children: [
Obx(
() => FilterChip(
label: const Text('Задачи'),
selected: controller.isTask.value,
onSelected: (bool selected) {
controller.isTask.value = selected;
},
selectedColor: Colors.blueAccent.withOpacity(0.1),
checkmarkColor: Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
const SizedBox(width: 8),
Obx(
() => FilterChip(
label: const Text('Проекты'),
selected: controller.isProj.value,
onSelected: (bool selected) {
controller.isProj.value = selected;
},
selectedColor: Colors.blueAccent.withOpacity(0.1),
checkmarkColor: Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
],
);
}
Widget _buildProjectsSection(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Projects',
style: AppStyles.sectionHeader.copyWith(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
SizedBox(
height: 160,
child: ListView.builder(
scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.only(right: 8),
itemCount: 4,
itemBuilder: (context, index) =>
_buildProjectCard(context, index + 1),
),
),
],
);
}
Widget _buildProjectCard(BuildContext context, int index) {
final projectColors = [
[Colors.indigo[900]!, Colors.indigo[400]!],
[Colors.blue[900]!, Colors.blue[400]!],
[Colors.red[900]!, Colors.red[400]!],
[Colors.green[900]!, Colors.green[400]!],
];
final titles = [
'Front End Development',
'Graphic Design',
'Graphic Design',
'Graphic Design',
];
final dates = [
'September 2020',
'October 2020',
'October 2020',
'October 2020',
];
return Padding(
padding: const EdgeInsets.only(right: 12),
child: Container(
width: 160,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: projectColors[index - 1],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(24),
),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.3),
shape: BoxShape.circle,
),
child: Icon(
EvaIcons.personOutline,
color: Colors.white,
size: 20,
),
),
const SizedBox(width: 8),
Text(
'Project $index',
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
],
),
const SizedBox(height: 12),
Text(
titles[index - 1],
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
dates[index - 1],
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 12,
),
),
],
),
),
);
}
Widget _buildProcessSection(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Активные задачи',
style: AppStyles.sectionHeader.copyWith(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Obx(() {
if (controller.tasks.isEmpty) {
return Center(child: Text('Нет активных задач'));
}
return RefreshIndicator(
onRefresh: () => controller.fetchTasks(),
child: Column(
children: controller.tasks
.map((task) => _buildProcessTaskCard(context, task))
.toList(),
),
);
}),
],
);
}
Widget _buildProcessTaskCard(BuildContext context, Task task) {
final now = DateTime.now();
final startDate = task.startTime;
String formatTime(DateTime dt) => dt.toString().substring(11, 16); // HH:mm
String formatDateTime(DateTime dt) {
if (dt.year == now.year && dt.month == now.month && dt.day == now.day) {
return 'Сегодня в ${formatTime(dt)}';
} else if (dt.year == now.year) {
return '${dt.day.toString().padLeft(2, '0')}.${dt.month.toString().padLeft(2, '0')} в ${formatTime(dt)}';
} else {
return '${dt.day.toString().padLeft(2, '0')}.${dt.month.toString().padLeft(2, '0')}.${dt.year} в ${formatTime(dt)}';
}
}
final int subtaskCount = task.subtasks?.length ?? 0;
final String subtaskLabel = subtaskCount == 1
? '1 пункт'
: subtaskCount < 5
? '$subtaskCount пункта'
: '$subtaskCount пунктов';
return InkWell(
onTap: () {
Get.dialog(_buildTaskExecutionDialog(task), barrierDismissible: true);
},
child: Container(
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 4,
spreadRadius: 1,
),
],
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.pink[50],
shape: BoxShape.circle,
),
child: Icon(
EvaIcons.shoppingCartOutline,
color: Colors.pink[400],
size: 24,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
task.title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
if (task.description.isNotEmpty == true)
Text(
task.description,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, color: Colors.grey[700]),
),
],
),
),
if (subtaskCount > 0)
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
formatDateTime(startDate),
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
if (subtaskCount > 0)
Text(
subtaskLabel,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
),
],
),
),
);
}
Widget _buildDrawer(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
Obx(
() => DrawerHeader(
decoration: BoxDecoration(color: Colors.blue[900]),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AdvancedAvatar(
name: controller.username.value,
autoTextSize: true,
size: 80,
statusAlignment: Alignment.topRight,
),
const SizedBox(height: 12),
Text(
controller.username.value,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
ListTile(
leading: const Icon(Icons.home),
title: const Text('Главная'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
leading: const Icon(Icons.calendar_today),
title: const Text('Задачи'),
onTap: () {
Navigator.pop(context);
Get.to(TasksScreen()); // Переход на страницу задач
},
),
ListTile(
leading: const Icon(Icons.settings),
title: const Text('Настройки'),
onTap: () {
Navigator.pop(context);
},
),
Divider(),
ListTile(
leading: const Icon(Icons.logout),
title: const Text('Выход'),
onTap: () {
// Логика выхода
Navigator.pop(context);
},
),
],
),
);
}
Widget _buildTaskExecutionDialog(Task task) {
return Dialog(
insetPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 60),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 500),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16),
child: StatefulBuilder(
builder: (context, setState) {
final bool isUnassigned = task.executor.isEmpty;
final bool allSubtasksDone =
task.items.isNotEmpty &&
task.items.every((item) => item.isDone);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
task.title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
if (task.description.isNotEmpty)
Text(
task.description,
style: const TextStyle(
fontSize: 15,
color: Colors.grey,
),
textAlign: TextAlign.center,
),
if (task.description.isNotEmpty) const SizedBox(height: 16),
if (task.items.isNotEmpty)
Column(
children: task.items
.map(
(item) => ListTile(
contentPadding: EdgeInsets.zero,
title: Text(item.text),
leading: item.isDone
? const Icon(
Icons.check_circle,
color: Colors.green,
)
: const Icon(
Icons.radio_button_unchecked,
color: Colors.grey,
),
onTap: () {
setState(() {
item.isDone = !item.isDone;
});
controller.updateTask(task);
},
),
)
.toList(),
),
// Автор — внизу, перед кнопками
if (task.author.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(
'Автор: ${task.author}',
style: const TextStyle(
fontSize: 13,
color: Colors.grey,
),
),
),
const SizedBox(height: 16),
// Кнопки
Wrap(
spacing: 12,
runSpacing: 8,
alignment: WrapAlignment.center,
children: [
// Кнопка "Взять заявку"
if (isUnassigned)
ElevatedButton(
onPressed: () {
controller.assignTaskToCurrentUser(task);
// Обновляем состояние, чтобы скрыть кнопку "Взять"
// и, возможно, показать новые данные
setState(() {});
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue[600],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
'Взять заявку',
style: TextStyle(color: Colors.white),
),
),
// Кнопка "Завершить" — появляется, если все подзадачи сделаны
if (allSubtasksDone)
ElevatedButton(
onPressed: () {
controller.completeTask(task);
Get.back(); // закрываем диалог ТОЛЬКО при завершении
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green[600],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
'Завершить',
style: TextStyle(color: Colors.white),
),
),
// Кнопка "Закрыть" — всегда доступна
OutlinedButton(
onPressed: Get.back,
style: OutlinedButton.styleFrom(
side: const BorderSide(color: Colors.grey),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text('Закрыть'),
),
],
),
],
);
},
),
),
),
),
);
}
}

View File

@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:Stocky/Pages/controllers/SplashScreenController.dart';
import 'package:get/get.dart';
class SplashScreen extends StatelessWidget {
const SplashScreen({super.key});
@override
Widget build(BuildContext context) {
// Автоматически создаём и привязываем контроллер к этому экрану
final controller = Get.put(SplashScreenController());
// Запускаем логику навигации один раз, когда виджет встроен в дерево
WidgetsBinding.instance.addPostFrameCallback((_) {
controller.navigateBasedOnAuth();
});
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
CircularProgressIndicator(),
SizedBox(height: 20),
Text('Загрузка...', style: TextStyle(fontSize: 18)),
],
),
),
);
}
}

View File

@@ -0,0 +1,211 @@
import 'package:flutter/material.dart';
import 'package:Stocky/Pages/controllers/MainController.dart';
import 'package:Stocky/classes/styles.dart';
import 'package:Stocky/models/task_adapter.dart';
import 'package:get/get.dart';
class TaskFormScreen extends StatefulWidget {
final Task? task;
const TaskFormScreen({super.key, this.task});
@override
State<TaskFormScreen> createState() => _TaskFormScreenState();
}
class _TaskFormScreenState extends State<TaskFormScreen> {
final _formKey = GlobalKey<FormState>();
final _titleController = TextEditingController();
final _descriptionController = TextEditingController();
final _itemsController = TextEditingController();
DateTime? _selectedDate;
List<Subtask> _items = [];
String _newItem = '';
@override
void initState() {
super.initState();
if (widget.task != null) {
_titleController.text = widget.task!.title;
_descriptionController.text = widget.task!.description;
_selectedDate = widget.task!.startTime;
_items = List.from(widget.task!.items);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.task != null ? 'Редактировать задачу' : 'Новая задача',
),
actions: [
TextButton(
onPressed: _saveTask,
child: const Text('Сохранить', style: TextStyle(fontSize: 16)),
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: ListView(
children: [
// Дата создания
ListTile(
title: Text(
_selectedDate != null
? 'Дата: ${_selectedDate!.day}.${_selectedDate!.month}.${_selectedDate!.year}'
: 'Выберите дату',
),
trailing: const Icon(Icons.calendar_today),
onTap: _selectDate,
),
TextFormField(
controller: _titleController,
decoration: const InputDecoration(
labelText: 'Название задачи',
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Введите название задачи';
}
return null;
},
),
const SizedBox(height: 16),
// Описание (опционально)
TextFormField(
controller: _descriptionController,
decoration: const InputDecoration(
labelText: 'Описание',
border: OutlineInputBorder(),
alignLabelWithHint: true,
),
maxLines: 3,
),
const SizedBox(height: 16),
// Пункты задачи (чеклист)
Text('Пункты задачи', style: AppStyles.titleSmall),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: TextField(
controller: _itemsController,
decoration: const InputDecoration(
labelText: 'Добавить пункт',
border: OutlineInputBorder(),
),
onChanged: (value) {
_newItem = value;
},
),
),
IconButton(icon: const Icon(Icons.add), onPressed: _addItem),
],
),
const SizedBox(height: 8),
// Список пунктов
if (_items.isNotEmpty)
..._items.map(
(item) => Card(
child: ListTile(
title: Text(item.text),
trailing: IconButton(
icon: const Icon(Icons.delete, color: Colors.red),
onPressed: () => _removeItem(item),
),
),
),
),
],
),
),
),
);
}
void _selectDate() async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: _selectedDate ?? DateTime.now(),
firstDate: DateTime(2020),
lastDate: DateTime(2101),
);
if (picked != null) {
setState(() {
_selectedDate = picked;
});
}
}
void _addItem() {
if (_newItem.trim().isNotEmpty) {
setState(() {
_items.add(
Subtask(
id: DateTime.now().microsecondsSinceEpoch.toString(),
text: _newItem.trim(),
isDone: false,
),
);
_itemsController.clear();
_newItem = '';
});
}
}
void _removeItem(Subtask item) {
setState(() {
_items.remove(item);
});
}
void _saveTask() {
if (_formKey.currentState!.validate()) {
final mainController = Get.find<MainController>();
String generateId() {
return DateTime.now().microsecondsSinceEpoch.toString();
}
final task = Task(
id: widget.task?.id ?? generateId(),
title: _titleController.text,
description: _descriptionController.text.trim(),
startTime: _selectedDate ?? DateTime.now(),
items: List.from(_items),
author: mainController.username.value,
executor: mainController.username.value,
isSynced: false,
isDeletedLocally: false,
);
try {
if (widget.task == null) {
mainController.addTask(task);
} else {
mainController.updateTask(task);
}
Get.back();
} catch (e) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Ошибка сохранения: $e')));
}
}
}
}

View File

@@ -0,0 +1,313 @@
// lib/Pages/views/tasks_screen.dart
import 'package:flutter/material.dart';
import 'package:Stocky/Pages/controllers/MainController.dart';
import 'package:Stocky/Pages/views/task_screen.dart';
import 'package:Stocky/classes/styles.dart';
import 'package:Stocky/models/task_adapter.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:swipeable_tile/swipeable_tile.dart';
import 'package:get/get.dart';
class TasksScreen extends GetWidget<MainController> {
const TasksScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.backgroundColor,
appBar: _buildAppBar(context),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildDateSelector(context),
const SizedBox(height: 20),
_buildTasksList(context),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// После создания — синхронизация не нужна: addTask сам всё делает
Get.to(() => const TaskFormScreen());
},
child: const Icon(Icons.add),
),
);
}
AppBar _buildAppBar(BuildContext context) {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
title: const Text(
'Sep 2020',
style: TextStyle(color: Colors.black87, fontWeight: FontWeight.bold),
),
actions: [
IconButton(
icon: Icon(EvaIcons.search, size: 26, color: Colors.blueGrey[700]),
onPressed: () {},
),
],
);
}
Widget _buildDateSelector(BuildContext context) {
return Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue[900],
borderRadius: BorderRadius.circular(24),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: List.generate(7, (index) {
final dayName = [
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
][index];
final dayNumber = 20 + index;
return GestureDetector(
onTap: () {
// Логика выбора даты (опционально)
},
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: dayNumber == 21 ? Colors.white : Colors.transparent,
borderRadius: BorderRadius.circular(20),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
dayName,
style: TextStyle(
fontSize: 10,
color: dayNumber == 21 ? Colors.blue[900] : Colors.white,
),
),
const SizedBox(height: 2),
Text(
dayNumber.toString(),
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: dayNumber == 21 ? Colors.blue[900] : Colors.white,
),
),
],
),
),
);
}),
),
);
}
Widget _buildTasksList(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Tasks',
style: AppStyles.sectionHeader.copyWith(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Obx(() {
// 🔑 ФИЛЬТРУЕМ: скрываем задачи, помеченные на удаление
final visibleTasks = controller.tasks
.where((task) => task.isDeletedLocally != true)
.toList();
if (visibleTasks.isEmpty) {
return Center(
child: Text(
'No tasks found',
style: TextStyle(color: Colors.grey[600]),
),
);
}
return Column(
children: visibleTasks
.map((task) => _buildTaskCard(context, task))
.toList(),
);
}),
],
);
}
Widget _buildTaskCard(BuildContext context, Task task) {
final startDate = task.startTime;
String formatTime(DateTime dt) => dt.toString().substring(11, 16); // HH:mm
return SwipeableTile.card(
color: Colors.white,
shadow: BoxShadow(
color: Colors.black.withOpacity(0.35),
blurRadius: 4,
offset: const Offset(2, 2),
),
key: ValueKey(task.id), // ← лучше использовать id, а не UniqueKey()
horizontalPadding: 8,
verticalPadding: 8,
child: InkWell(
onTap: () {
Get.dialog(_buildTaskExecutionDialog(task), barrierDismissible: true);
},
onLongPress: () => Get.to(
TaskFormScreen(task: task),
), // ← синхронизация происходит автоматически через updateTask
borderRadius: BorderRadius.circular(16),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.pink[50],
shape: BoxShape.circle,
),
child: Icon(
_getTaskIcon('meeting'),
size: 24,
color: Colors.pink[400],
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
task.title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
'${formatTime(startDate)} to ${formatTime(startDate.add(Duration(hours: 2)))}',
style: const TextStyle(
fontSize: 13,
color: Colors.grey,
height: 1.4,
),
),
],
),
),
IconButton(
onPressed: () {
// Доп. действия (например, меню)
},
icon: const Icon(Icons.more_vert, color: Colors.grey),
),
],
),
),
),
onSwiped: (direction) => controller.deleteTask(task),
backgroundBuilder: (context, direction, progress) {
return Container(
color: Colors.redAccent,
child: const Align(
alignment: Alignment.centerRight,
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Удалить',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
);
},
);
}
IconData _getTaskIcon(String category) {
switch (category.toLowerCase()) {
case 'client call':
return Icons.phone_rounded;
default:
return EvaIcons.shoppingCartOutline;
}
}
Widget _buildTaskExecutionDialog(Task task) {
// Здесь можно реализовать логику выполнения подзадач
// Пока оставим как есть (без сохранения изменений)
return Material(
color: Colors.transparent,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
),
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
task.title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Text(task.description, style: const TextStyle(fontSize: 16)),
const SizedBox(height: 16),
...task.items.map(
(item) => ListTile(
title: Text(item.text),
leading: item.isDone
? const Icon(Icons.check_circle, color: Colors.green)
: const Icon(Icons.radio_button_unchecked),
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(onPressed: Get.back, child: const Text('Закрыть')),
],
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,77 @@
import 'package:flutter/services.dart';
class PhoneInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
// Если ввод пустой — возвращаем его как есть
if (newValue.text.isEmpty) {
return newValue;
}
// Убираем все нецифровые символы из ввода
String input = newValue.text.replaceAll(RegExp(r'[^0-9]'), '');
// Ограничиваем длину — максимум 11 цифр (без +7)
if (input.length > 11) {
input = input.substring(0, 11);
}
// Применяем маску
String formatted = _applyPhoneMask(input);
// Возвращаем отформатированное значение, сохраняя курсор
return newValue.copyWith(
text: formatted,
selection: TextSelection.collapsed(
offset: _getCursorOffset(input, formatted),
),
);
}
// Применяет маску +7 (XXX) XXX-XX-XX
String _applyPhoneMask(String digits) {
if (digits.isEmpty) return '';
if (digits.length == 1) return '+7';
if (digits.length == 2) return '+7 (${'$digits'.substring(1, 2)})';
if (digits.length == 3) return '+7 (${digits.substring(1)})';
if (digits.length == 4) return '+7 (${digits.substring(1, 4)})';
if (digits.length == 5)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 5)}';
if (digits.length == 6)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 6)}';
if (digits.length == 7)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 7)}';
if (digits.length == 8)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 7)}-${digits.substring(7, 8)}';
if (digits.length == 9)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 7)}-${digits.substring(7, 9)}';
if (digits.length == 10)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 7)}-${digits.substring(7, 9)}-${digits.substring(9, 10)}';
if (digits.length == 11)
return '+7 (${digits.substring(1, 4)}) ${digits.substring(4, 7)}-${digits.substring(7, 9)}-${digits.substring(9, 11)}';
return digits;
}
// Вычисляет новую позицию курсора после форматирования
int _getCursorOffset(String oldDigits, String formatted) {
// Если ввод был короче — курсор должен быть в конце
if (oldDigits.length >= formatted.length) {
return formatted.length;
}
// Сопоставляем позиции: сколько цифр было до текущей позиции
int cursorPosition = 0;
for (int i = 0; i < oldDigits.length; i++) {
String before = _applyPhoneMask(oldDigits.substring(0, i + 1));
String after = _applyPhoneMask(oldDigits.substring(0, i + 2));
if (after.length > before.length) {
cursorPosition++;
}
}
return cursorPosition;
}
}

114
lib/classes/styles.dart Normal file
View File

@@ -0,0 +1,114 @@
import 'package:flutter/material.dart';
class AppStyles {
// Заголовки
static const TextStyle title = TextStyle(
fontSize: 20,
fontWeight: FontWeight.w900,
fontFamily: 'Geologica',
color: Colors.black87,
);
static const TextStyle titleLarge = TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
fontFamily: 'Geologica',
color: Colors.black87,
);
static const TextStyle titleSmall = TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Geologica',
color: Colors.black87,
);
// Тексты группировки/разделов
static const TextStyle sectionHeader = TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
fontFamily: 'Geologica',
color: Colors.black87,
);
// Основной текст
static const TextStyle body = TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
fontFamily: 'Geologica',
color: Colors.black87,
);
// Описание/вспомогательный текст
static const TextStyle description = TextStyle(
fontSize: 12,
fontWeight: FontWeight.normal,
fontFamily: 'Geologica',
color: Colors.grey,
);
// Мелкий текст
static const TextStyle caption = TextStyle(
fontSize: 10,
fontWeight: FontWeight.normal,
fontFamily: 'Geologica',
color: Colors.grey,
);
// Ссылки и кликабельные элементы
static const TextStyle link = TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
fontFamily: 'Geologica',
color: Colors.blue,
decoration: TextDecoration.underline,
);
// Статусы
static const TextStyle statusActive = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Geologica',
color: Colors.orange,
);
static const TextStyle statusCompleted = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Geologica',
color: Colors.green,
);
static const TextStyle statusPending = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Geologica',
color: Colors.blue,
);
// Стили для иконок
static const double iconSizeLarge = 32.0;
static const double iconSizeMedium = 24.0;
static const double iconSizeSmall = 16.0;
static const Color iconColorPrimary = Colors.blue;
static const Color iconColorSecondary = Colors.grey;
static const Color iconColorAccent = Colors.orange;
// Вспомогательные методы для иконок
static Icon createPrimaryIcon(IconData icon, {double? size}) {
return Icon(icon, size: size ?? iconSizeMedium, color: iconColorPrimary);
}
static Icon createSecondaryIcon(IconData icon, {double? size}) {
return Icon(icon, size: size ?? iconSizeMedium, color: iconColorSecondary);
}
static Icon createAccentIcon(IconData icon, {double? size}) {
return Icon(icon, size: size ?? iconSizeMedium, color: iconColorAccent);
}
}
class AppColors {
static const Color backgroundColor = Color(0xFFF8F9FC);
}

74
lib/firebase_options.dart Normal file
View File

@@ -0,0 +1,74 @@
// File generated by FlutterFire CLI.
// ignore_for_file: type=lint
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;
/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for ios - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
return windows;
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
static const FirebaseOptions web = FirebaseOptions(
apiKey: 'AIzaSyDf-atQsOTsyNlPXgc8yamPEo0P77vU72g',
appId: '1:785043562091:web:bae3c514d31ac7ce7c5b2e',
messagingSenderId: '785043562091',
projectId: 'apllicationswork',
authDomain: 'apllicationswork.firebaseapp.com',
storageBucket: 'apllicationswork.firebasestorage.app',
);
static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyBGgbGEs6fe9jJgyIWjsRaCmrifC4pjxQo',
appId: '1:785043562091:android:abc115731c662f297c5b2e',
messagingSenderId: '785043562091',
projectId: 'apllicationswork',
storageBucket: 'apllicationswork.firebasestorage.app',
);
static const FirebaseOptions windows = FirebaseOptions(
apiKey: 'AIzaSyDf-atQsOTsyNlPXgc8yamPEo0P77vU72g',
appId: '1:785043562091:web:6f0beb2b421d6ba27c5b2e',
messagingSenderId: '785043562091',
projectId: 'apllicationswork',
authDomain: 'apllicationswork.firebaseapp.com',
storageBucket: 'apllicationswork.firebasestorage.app',
);
}

49
lib/main.dart Normal file
View File

@@ -0,0 +1,49 @@
import 'package:Stocky/services/api/push_notification_service.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:Stocky/Pages/controllers/MainController.dart';
import 'package:Stocky/Pages/views/login_screen.dart';
import 'package:Stocky/Pages/views/main_screen.dart';
import 'package:Stocky/Pages/views/splash_screen.dart';
import 'package:Stocky/services/api/api_service.dart';
import 'package:Stocky/services/local/StorageService.dart';
import 'firebase_options.dart';
import 'package:get/get.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LocalStorageService.init();
await ApiService.init();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
Get.put(PushNotificationService());
//Подключаем контроллер
Get.lazyPut(() => MainController());
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Авторизация',
debugShowCheckedModeBanner: false,
initialRoute: '/',
getPages: [
GetPage(name: '/', page: () => SplashScreen()),
GetPage(name: '/login', page: () => LoginScreen()),
GetPage(name: '/home', page: () => HomeScreen()),
],
);
}
}

View File

@@ -0,0 +1,5 @@
class Document {
int? id;
Document({this.id});
}

View File

@@ -0,0 +1,117 @@
// task_adapter.dart
import 'package:hive/hive.dart';
part 'task_adapter.g.dart';
@HiveType(typeId: 0)
class Task extends HiveObject {
@HiveField(0)
final String id;
@HiveField(1)
final String title;
@HiveField(3)
String description;
@HiveField(4)
final String author;
@HiveField(5)
String executor;
@HiveField(6)
final DateTime startTime;
@HiveField(7)
DateTime? endTime;
@HiveField(8)
bool isCompleted;
@HiveField(9)
bool isSynced;
@HiveField(10) // Новое поле: список подзадач
final List<Subtask> items;
@HiveField(11)
bool isDeletedLocally;
@HiveField(12)
bool isNew;
Task({
required this.id,
required this.title,
required this.startTime,
required this.author,
required this.executor,
this.endTime,
this.isCompleted = false,
this.description = "",
this.isSynced = false,
this.isDeletedLocally = false,
this.items = const [],
this.isNew = true,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'title': title,
'startTime': startTime.toIso8601String(),
'endTime': endTime?.toIso8601String() ?? '',
'author': author,
'executor': executor,
'isCompleted': isCompleted,
'description': description,
'items': items.map((item) => item.toMap()).toList(),
};
}
factory Task.fromMap(Map<String, dynamic> map) {
return Task(
id: map['_id'],
title: map['title'],
description: map['description'],
author: map['author'],
executor: map['executor'],
startTime: DateTime.parse(map['startTime']),
endTime: map['endTime'] != null ? DateTime.parse(map['endTime']) : null,
isCompleted: map['isCompleted'],
isSynced: true,
isDeletedLocally: false,
isNew: false,
items:
(map['items'] as List?)
?.map((item) => Subtask.fromMap(item))
.toList() ??
[],
);
}
get subtasks => items;
}
@HiveType(typeId: 1)
class Subtask extends HiveObject {
@HiveField(0)
final String id;
@HiveField(1)
String text;
@HiveField(2)
bool isDone;
Subtask({required this.id, required this.text, this.isDone = false});
Map<String, dynamic> toMap() {
return {'id': id, 'text': text, 'isDone': isDone};
}
factory Subtask.fromMap(Map<String, dynamic> map) {
return Subtask(id: map['id'], text: map['text'], isDone: map['isDone']);
}
}

View File

@@ -0,0 +1,114 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'task_adapter.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class TaskAdapter extends TypeAdapter<Task> {
@override
final int typeId = 0;
@override
Task read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Task(
id: fields[0] as String,
title: fields[1] as String,
startTime: fields[6] as DateTime,
author: fields[4] as String,
executor: fields[5] as String,
endTime: fields[7] as DateTime?,
isCompleted: fields[8] as bool,
description: fields[3] as String,
isSynced: fields[9] as bool,
isDeletedLocally: fields[11] as bool,
items: (fields[10] as List).cast<Subtask>(),
isNew: fields[12] as bool,
);
}
@override
void write(BinaryWriter writer, Task obj) {
writer
..writeByte(12)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.title)
..writeByte(3)
..write(obj.description)
..writeByte(4)
..write(obj.author)
..writeByte(5)
..write(obj.executor)
..writeByte(6)
..write(obj.startTime)
..writeByte(7)
..write(obj.endTime)
..writeByte(8)
..write(obj.isCompleted)
..writeByte(9)
..write(obj.isSynced)
..writeByte(10)
..write(obj.items)
..writeByte(11)
..write(obj.isDeletedLocally)
..writeByte(12)
..write(obj.isNew);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is TaskAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class SubtaskAdapter extends TypeAdapter<Subtask> {
@override
final int typeId = 1;
@override
Subtask read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Subtask(
id: fields[0] as String,
text: fields[1] as String,
isDone: fields[2] as bool,
);
}
@override
void write(BinaryWriter writer, Subtask obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.text)
..writeByte(2)
..write(obj.isDone);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SubtaskAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -0,0 +1,170 @@
// lib/services/api/api_service.dart
import 'package:flutter/material.dart';
import 'package:Stocky/models/task_adapter.dart';
import 'package:Stocky/services/local/StorageService.dart';
import 'package:Stocky/utils/constants.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart';
class ApiService extends GetxService {
static final ApiService _instance = ApiService._internal();
ApiService._internal() {
_setupDio();
}
final Dio _dio = Dio();
String? get accessToken => Get.find<LocalStorageService>().getAccessToken();
factory ApiService() => _instance;
void _setupDio() {
_dio.options.baseUrl = Constants.BASE_URL;
_dio.options.connectTimeout = const Duration(seconds: 10);
_dio.options.receiveTimeout = const Duration(seconds: 10);
_dio.options.contentType = Headers.jsonContentType;
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
final token = accessToken;
if (token != null) {
options.headers['Authorization'] = 'Bearer $token';
}
return handler.next(options);
},
onResponse: (response, handler) => handler.next(response),
),
);
}
Future registerByPhone(String phone) async {
try {
await _dio.post(
'/register',
data: {'application': 'warehouse', 'phone': phone},
);
} catch (e) {
debugPrint('Регистрация по телефону: $e');
}
}
Future<bool> loginByPhone(String phone, String digCode) async {
try {
final response = await _dio.post(
'/login',
data: {
'phone': phone,
'digCode': digCode,
'application': 'warehouse',
}, // ← убран пробел
);
if (response.statusCode == 200) {
final data = response.data;
final token = data['token'];
final username = data['name'];
Get.find<LocalStorageService>().saveAccessToken(token);
Get.find<LocalStorageService>().putUsername(username);
return true;
}
} catch (e) {
debugPrint('Логин по телефону: $e');
}
return false;
}
Future<List<Task>> fetchTasks() async {
try {
final username = await Get.find<LocalStorageService>().getUsername();
final response = await _dio.get('/warehouse/tasks/$username');
if (response.statusCode == 200) {
final List<dynamic> list = response.data;
return list.map((item) => Task.fromMap(item)).toList();
} else {
debugPrint(
'Некорректный статус при загрузке задач: ${response.statusCode}',
);
}
} catch (e) {
debugPrint('Ошибка загрузки задач: $e');
}
return [];
}
Future<Task?> upsertTask(Task task) async {
if (task.isNew == true || task.id.isEmpty) {
final saved = await saveTask(task);
return saved;
} else {
final success = await updateTask(task);
return success ? task : null;
}
}
Future<Task?> saveTask(Task task) async {
try {
final response = await _dio.post('/warehouse/task', data: task.toMap());
if (response.statusCode == 200) {
return response.data;
}
} catch (e) {
debugPrint('Ошибка сохранения задачи: $e');
}
return null;
}
Future<bool> updateTask(Task task) async {
try {
debugPrint('Обновление задачи: ${task.toMap()}');
final response = await _dio.put('/warehouse/task', data: task.toMap());
return response.statusCode == 201;
} catch (e) {
debugPrint('Ошибка обновления задачи: $e');
}
return false;
}
Future<bool> deleteTask(String taskId) async {
try {
final response = await _dio.delete('/warehouse/task/$taskId');
return response.statusCode == 200;
} catch (e) {
debugPrint('Ошибка удаления задачи: $e');
}
return false;
}
void clearAuth() {
Get.find<LocalStorageService>().clearAuth();
}
static Future<ApiService> init() async {
final service = ApiService();
Get.put(service, permanent: true);
return service;
}
Future<bool> setFcmToken(String token) async {
try {
final response = await _dio.put(
'/warehouse/user',
data: {
"number": await Get.find<LocalStorageService>().getNumber(),
"notification": {
"token": token.toString(),
"enable": true,
"type": "FCM",
},
},
);
return response.statusCode == 200;
} catch (e) {
debugPrint('Ошибка обновление токена: $e');
}
return false;
}
}

View File

@@ -0,0 +1,151 @@
// lib/services/api/push_notification_service.dart
import 'dart:async';
import 'package:Stocky/Pages/controllers/MainController.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'api_service.dart'; // Убедитесь, что путь правильный
class PushNotificationService extends GetxService {
final FirebaseMessaging _messaging = FirebaseMessaging.instance;
final StreamController<String?> _tokenController =
StreamController<String?>.broadcast();
final StreamController<RemoteMessage> _foregroundMessageController =
StreamController<RemoteMessage>.broadcast();
// Поток для уведомлений, пришедших при открытом приложении
Stream<RemoteMessage> get foregroundMessageStream =>
_foregroundMessageController.stream;
// Поток FCM-токена
Stream<String?> get tokenStream => _tokenController.stream;
@override
void onInit() {
_initFirebase();
super.onInit();
}
@override
void onClose() {
_tokenController.close();
_foregroundMessageController.close();
super.onClose();
}
Future<void> _initFirebase() async {
try {
await Firebase.initializeApp();
// Запрашиваем разрешение
await _requestPermission();
// Получаем токен
await _getToken();
// Настраиваем обработчики
_setupMessageHandling();
} catch (e) {
debugPrint('Ошибка инициализации FCM: $e');
}
}
Future<void> _requestPermission() async {
final status = await _messaging.requestPermission(
alert: true,
badge: true,
sound: true,
// остальные по умолчанию false
);
if (status.authorizationStatus == AuthorizationStatus.authorized ||
status.authorizationStatus == AuthorizationStatus.provisional) {
debugPrint('Разрешение на уведомления получено');
} else {
debugPrint('Разрешение отклонено');
}
}
Future<void> _getToken() async {
try {
final String? token = await _messaging.getToken();
if (token != null) {
_tokenController.add(token);
print('FCM Token: $token');
// Отправляем токен на сервер — но только если ApiService уже инициализирован
if (Get.isRegistered<ApiService>()) {
Get.find<ApiService>().setFcmToken(token);
} else {
// Опционально: сохраните токен локально и отправьте позже
print('ApiService не готов — токен временно не отправлен');
}
}
} catch (e) {
debugPrint('Ошибка получения токена FCM: $e');
}
}
void _setupMessageHandling() {
// Уведомления, пришедшие при открытом приложении
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
debugPrint('Уведомление в foreground: ${message.notification?.title}');
Get.find<MainController>().fetchTasks();
_foregroundMessageController.add(message); // ← Передаём дальше
});
// Пользователь нажал на уведомление из фонового режима
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
debugPrint('Уведомление открыто из фона: ${message.notification?.title}');
_handleMessageAction(message);
});
// Фоновый обработчик (для закрытого приложения)
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}
// Обработка действия из уведомления
void _handleMessageAction(RemoteMessage message) {
final data = message.data;
// Пример: действие зависит от поля "action" в payload
final action = data['action'];
switch (action) {
case 'open_task':
final taskId = data['task_id'];
if (taskId != null) {
// Здесь можно вызвать навигацию или обновить состояние
// Например, через Get.toNamed('/task/$taskId');
// Но лучше делегировать это MainController или другому слушателю
Get.find<MainController>().openTaskFromNotification(taskId);
}
break;
case 'refresh_tasks':
if (Get.isRegistered<MainController>()) {
Get.find<MainController>().fetchTasks();
}
break;
// Добавьте другие действия по мере необходимости
default:
debugPrint('Неизвестное действие: $action');
}
}
// Статический фоновый обработчик (ограниченный функционал)
static Future<void> _firebaseMessagingBackgroundHandler(
RemoteMessage message,
) async {
// В фоне нельзя использовать GetX, Dio с авторизацией и т.п.
// Только простые операции: логирование, запись в Hive и т.д.
debugPrint('Фоновое уведомление: ${message.messageId}');
// Пример: сохранить в локальную БД, чтобы обработать при запуске
}
}

View File

@@ -0,0 +1,88 @@
// lib/services/api/socket_service.dart
import 'dart:convert';
import 'package:flutter_stocky/utils/constants.dart';
import 'package:get/get.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
class SocketService extends GetxService {
final String _baseUrl = Constants.BASE_SOCKET_URL;
WebSocketChannel? _channel;
bool _connected = false;
// Поток для получения сообщений
StreamController<Map<String, dynamic>> _messageController =
StreamController.broadcast();
Stream<Map<String, dynamic>> get messages => _messageController.stream;
@override
void onInit() {
connect();
super.onInit();
}
@override
void onClose() {
_disconnect();
_messageController.close();
super.onClose();
}
void connect() async {
if (_connected) return;
try {
_channel = WebSocketChannel.connect(Uri.parse('$_baseUrl/ws'));
_channel!.stream.listen(
(message) {
final data = json.decode(message);
_messageController.add(data);
},
onDone: () {
_connected = false;
debugPrint('WebSocket отключен');
},
onError: (error) {
debugPrint('WebSocket ошибка: $error');
_connected = false;
// Автоподключение через 3 сек
Future.delayed(const Duration(seconds: 3), connect);
},
);
_connected = true;
debugPrint('WebSocket подключен');
} catch (e) {
debugPrint('Ошибка подключения к WebSocket: $e');
}
}
void _disconnect() {
_channel?.close();
_channel = null;
_connected = false;
}
void sendMessage(Map<String, dynamic> message) {
if (_connected && _channel != null) {
_channel?.sink.add(json.encode(message));
}
}
// Пример: отправить обновление задачи
void notifyTaskUpdate(String taskId) {
sendMessage({'type': 'task_updated', 'task_id': taskId});
}
// Пример: подписаться на изменения задач
void subscribeToTasks() {
sendMessage({'type': 'subscribe', 'entity': 'tasks'});
}
// Пример: уведомить о создании задачи
void notifyTaskCreated(Task task) {
sendMessage({'type': 'task_created', 'data': task.toJson()});
}
bool get isConnected => _connected;
}

View File

@@ -0,0 +1,106 @@
// lib/services/local/local_storage_service.dart
import 'package:Stocky/models/task_adapter.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
class LocalStorageService extends GetxService {
static final LocalStorageService _instance = LocalStorageService._internal();
late Box _settBox;
late Box<Task> _tasksBox;
late Box _docsBox;
LocalStorageService._internal();
factory LocalStorageService() => _instance;
Box get settingsBox => _settBox;
Box<Task> get tasksBox => _tasksBox;
Box get docsBox => _docsBox;
List<Task> getTasks() {
return tasksBox.values.toList();
}
Future<List<Task>> getCompletedTasks() async {
return tasksBox.values.where((task) => !task.isCompleted).toList();
}
Future<void> putNumber(String number) async {
await settingsBox.put('number', number);
}
Future<String> getNumber() async {
return settingsBox.get('number');
}
Future<void> putUsername(String name) async {
await settingsBox.put('username', name);
}
Future<String> getUsername() async {
return settingsBox.get('username', defaultValue: 'john doe');
}
Future<void> saveTasks(List<Task> tasks) async {
await tasksBox.clear();
for (final task in tasks) {
await tasksBox.put(task.id.toString(), task);
}
}
Future<void> addTask(Task task) async {
await tasksBox.put(task.id.toString(), task);
}
Future<void> updateTask(Task task) async {
await tasksBox.put(task.id.toString(), task);
}
Future<void> replaceTask(String oldId, Task newTask) async {
await tasksBox.delete(oldId);
await tasksBox.put(newTask.id.toString(), newTask);
}
Future<void> removeTask(dynamic taskId) async {
await tasksBox.delete(taskId.toString());
}
// --- Токены ---
Future<void> saveAccessToken(String token) async {
await settingsBox.put('access_token', token);
}
Future<void> clearAuth() async {
await settingsBox.delete('access_token');
}
Future<void> saveFcmToken(String token) async {
await settingsBox.put('fcm_token', token);
}
String? getAccessToken() => settingsBox.get('access_token');
String? getFcmToken() => settingsBox.get('fcm_token');
static Future<LocalStorageService> init() async {
await Hive.initFlutter();
Hive.registerAdapter(TaskAdapter());
Hive.registerAdapter(SubtaskAdapter());
// Открываем боксы
await Hive.openBox('settings');
await Hive.openBox<Task>('tasks');
await Hive.openBox('docs');
// Теперь можно безопасно получить ссылки
final service = _instance;
service._settBox = Hive.box('settings');
service._tasksBox = Hive.box<Task>('tasks');
service._docsBox = Hive.box('docs');
Get.put(service, permanent: true);
return service;
}
}

5
lib/utils/constants.dart Normal file
View File

@@ -0,0 +1,5 @@
// lib/utils/constants.dart
class Constants {
static const String BASE_URL = 'http://service.74033.ru:3000/';
// static const String BASE_SOCKET_URL = 'ws://service.74033.ru:3000/warehouse';
}

975
pubspec.lock Normal file
View File

@@ -0,0 +1,975 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab"
url: "https://pub.dev"
source: hosted
version: "76.0.0"
_flutterfire_internals:
dependency: transitive
description:
name: _flutterfire_internals
sha256: cd83f7d6bd4e4c0b0b4fef802e8796784032e1cc23d7b0e982cf5d05d9bbe182
url: "https://pub.dev"
source: hosted
version: "1.3.66"
_macros:
dependency: transitive
description: dart
source: sdk
version: "0.3.3"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e"
url: "https://pub.dev"
source: hosted
version: "6.11.0"
ansi_styles:
dependency: transitive
description:
name: ansi_styles
sha256: "9c656cc12b3c27b17dd982b2cc5c0cfdfbdabd7bc8f3ae5e8542d9867b47ce8a"
url: "https://pub.dev"
source: hosted
version: "0.3.2+1"
args:
dependency: transitive
description:
name: args
sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
url: "https://pub.dev"
source: hosted
version: "2.7.0"
async:
dependency: transitive
description:
name: async
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
url: "https://pub.dev"
source: hosted
version: "2.13.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
build:
dependency: transitive
description:
name: build
sha256: "51dc711996cbf609b90cbe5b335bbce83143875a9d58e4b5c6d3c4f684d3dda7"
url: "https://pub.dev"
source: hosted
version: "2.5.4"
build_config:
dependency: transitive
description:
name: build_config
sha256: "4ae2de3e1e67ea270081eaee972e1bd8f027d459f249e0f1186730784c2e7e33"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
build_daemon:
dependency: transitive
description:
name: build_daemon
sha256: bf05f6e12cfea92d3c09308d7bcdab1906cd8a179b023269eed00c071004b957
url: "https://pub.dev"
source: hosted
version: "4.1.1"
build_resolvers:
dependency: transitive
description:
name: build_resolvers
sha256: ee4257b3f20c0c90e72ed2b57ad637f694ccba48839a821e87db762548c22a62
url: "https://pub.dev"
source: hosted
version: "2.5.4"
build_runner:
dependency: "direct dev"
description:
name: build_runner
sha256: "382a4d649addbfb7ba71a3631df0ec6a45d5ab9b098638144faf27f02778eb53"
url: "https://pub.dev"
source: hosted
version: "2.5.4"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
sha256: "85fbbb1036d576d966332a3f5ce83f2ce66a40bea1a94ad2d5fc29a19a0d3792"
url: "https://pub.dev"
source: hosted
version: "9.1.2"
built_collection:
dependency: transitive
description:
name: built_collection
sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100"
url: "https://pub.dev"
source: hosted
version: "5.1.1"
built_value:
dependency: transitive
description:
name: built_value
sha256: "7931c90b84bc573fef103548e354258ae4c9d28d140e41961df6843c5d60d4d8"
url: "https://pub.dev"
source: hosted
version: "8.12.3"
characters:
dependency: transitive
description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
version: "1.4.0"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
sha256: "959525d3162f249993882720d52b7e0c833978df229be20702b33d48d91de70f"
url: "https://pub.dev"
source: hosted
version: "2.0.4"
ci:
dependency: transitive
description:
name: ci
sha256: "145d095ce05cddac4d797a158bc4cf3b6016d1fe63d8c3d2fbd7212590adca13"
url: "https://pub.dev"
source: hosted
version: "0.1.0"
cli_util:
dependency: transitive
description:
name: cli_util
sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
url: "https://pub.dev"
source: hosted
version: "0.4.2"
clock:
dependency: transitive
description:
name: clock
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
url: "https://pub.dev"
source: hosted
version: "1.1.2"
code_builder:
dependency: transitive
description:
name: code_builder
sha256: "6a6cab2ba4680d6423f34a9b972a4c9a94ebe1b62ecec4e1a1f2cba91fd1319d"
url: "https://pub.dev"
source: hosted
version: "4.11.1"
collection:
dependency: transitive
description:
name: collection
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
url: "https://pub.dev"
source: hosted
version: "1.19.1"
convert:
dependency: transitive
description:
name: convert
sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68
url: "https://pub.dev"
source: hosted
version: "3.1.2"
crypto:
dependency: transitive
description:
name: crypto
sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
url: "https://pub.dev"
source: hosted
version: "3.0.7"
dart_console:
dependency: transitive
description:
name: dart_console
sha256: dfa4b63eb4382325ff975fdb6b7a0db8303bb5809ee5cb4516b44153844742ed
url: "https://pub.dev"
source: hosted
version: "1.2.0"
dart_style:
dependency: transitive
description:
name: dart_style
sha256: "7306ab8a2359a48d22310ad823521d723acfed60ee1f7e37388e8986853b6820"
url: "https://pub.dev"
source: hosted
version: "2.3.8"
deep_pick:
dependency: transitive
description:
name: deep_pick
sha256: "79d96b94a9c9ca2e823f05f72ec1a4efcc5ad5fd3875f46d1a8fe61ebbd9f359"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
dio:
dependency: "direct dev"
description:
name: dio
sha256: d90ee57923d1828ac14e492ca49440f65477f4bb1263575900be731a3dac66a9
url: "https://pub.dev"
source: hosted
version: "5.9.0"
dio_web_adapter:
dependency: transitive
description:
name: dio_web_adapter
sha256: "7586e476d70caecaf1686d21eee7247ea43ef5c345eab9e0cc3583ff13378d78"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
eva_icons_flutter:
dependency: "direct dev"
description:
name: eva_icons_flutter
sha256: "6d48a10b93590ab83eb092bee5adacdeb14f3d83f527a4b9e4092c363d56e2a8"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
extended_masked_text:
dependency: "direct dev"
description:
name: extended_masked_text
sha256: "1599e6c2cea0b24214114c92679cf2c56cd9c8c1cac5dfc65c292bf3373b4b33"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
fake_async:
dependency: transitive
description:
name: fake_async
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
url: "https://pub.dev"
source: hosted
version: "1.3.3"
ffi:
dependency: transitive
description:
name: ffi
sha256: d07d37192dbf97461359c1518788f203b0c9102cfd2c35a716b823741219542c
url: "https://pub.dev"
source: hosted
version: "2.1.5"
file:
dependency: transitive
description:
name: file
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
url: "https://pub.dev"
source: hosted
version: "7.0.1"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
sha256: "923085c881663ef685269b013e241b428e1fb03cdd0ebde265d9b40ff18abf80"
url: "https://pub.dev"
source: hosted
version: "4.4.0"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
sha256: cccb4f572325dc14904c02fcc7db6323ad62ba02536833dddb5c02cac7341c64
url: "https://pub.dev"
source: hosted
version: "6.0.2"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
sha256: "83e7356c704131ca4d8d8dd57e360d8acecbca38b1a3705c7ae46cc34c708084"
url: "https://pub.dev"
source: hosted
version: "3.4.0"
firebase_messaging:
dependency: "direct main"
description:
name: firebase_messaging
sha256: "06fad40ea14771e969a8f2bbce1944aa20ee2f4f57f4eca5b3ba346b65f3f644"
url: "https://pub.dev"
source: hosted
version: "16.1.1"
firebase_messaging_platform_interface:
dependency: transitive
description:
name: firebase_messaging_platform_interface
sha256: "6c49e901c77e6e10e86d98e32056a087eb1ca1b93acdf58524f1961e617657b7"
url: "https://pub.dev"
source: hosted
version: "4.7.6"
firebase_messaging_web:
dependency: transitive
description:
name: firebase_messaging_web
sha256: "2756f8fea583ffb9d294d15ddecb3a9ad429b023b70c9990c151fc92c54a32b3"
url: "https://pub.dev"
source: hosted
version: "4.1.2"
fixnum:
dependency: transitive
description:
name: fixnum
sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be
url: "https://pub.dev"
source: hosted
version: "1.1.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_advanced_avatar:
dependency: "direct main"
description:
name: flutter_advanced_avatar
sha256: c97fa65a2499d85f367421b8386d45ce090046dcf24f6f71042e5e4e5c6a8c59
url: "https://pub.dev"
source: hosted
version: "1.5.2"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1"
url: "https://pub.dev"
source: hosted
version: "6.0.0"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
sha256: "87fbd7c534435b6c5d9d98b01e1fd527812b82e68ddd8bd35fc45ed0fa8f0a95"
url: "https://pub.dev"
source: hosted
version: "2.2.3"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutterfire_cli:
dependency: "direct main"
description:
name: flutterfire_cli
sha256: "1c405f181130fcf8f85f3d9ec320660bdf36fb7a40632f538a124bb798d612db"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694
url: "https://pub.dev"
source: hosted
version: "4.0.0"
get:
dependency: "direct dev"
description:
name: get
sha256: "5ed34a7925b85336e15d472cc4cfe7d9ebf4ab8e8b9f688585bf6b50f4c3d79a"
url: "https://pub.dev"
source: hosted
version: "4.7.3"
glob:
dependency: transitive
description:
name: glob
sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de
url: "https://pub.dev"
source: hosted
version: "2.1.3"
graphs:
dependency: transitive
description:
name: graphs
sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
hive:
dependency: "direct dev"
description:
name: hive
sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941"
url: "https://pub.dev"
source: hosted
version: "2.2.3"
hive_flutter:
dependency: "direct dev"
description:
name: hive_flutter
sha256: dca1da446b1d808a51689fb5d0c6c9510c0a2ba01e22805d492c73b68e33eecc
url: "https://pub.dev"
source: hosted
version: "1.1.0"
hive_generator:
dependency: "direct dev"
description:
name: hive_generator
sha256: "06cb8f58ace74de61f63500564931f9505368f45f98958bd7a6c35ba24159db4"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
http:
dependency: transitive
description:
name: http
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
url: "https://pub.dev"
source: hosted
version: "1.6.0"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
sha256: aa6199f908078bb1c5efb8d8638d4ae191aac11b311132c3ef48ce352fb52ef8
url: "https://pub.dev"
source: hosted
version: "3.2.2"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
url: "https://pub.dev"
source: hosted
version: "4.1.2"
hugeicons:
dependency: "direct main"
description:
name: hugeicons
sha256: d19c0e2b57ccf455dd8ef08b84da40ae6dbba898c92960a0a0ada77df7865b8a
url: "https://pub.dev"
source: hosted
version: "1.1.5"
interact:
dependency: transitive
description:
name: interact
sha256: b1abf79334bec42e58496a054cb7ee7ca74da6181f6a1fb6b134f1aa22bc4080
url: "https://pub.dev"
source: hosted
version: "2.2.0"
intl:
dependency: transitive
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.18.1"
io:
dependency: transitive
description:
name: io
sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b
url: "https://pub.dev"
source: hosted
version: "1.0.5"
js:
dependency: transitive
description:
name: js
sha256: "53385261521cc4a0c4658fd0ad07a7d14591cf8fc33abbceae306ddb974888dc"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
url: "https://pub.dev"
source: hosted
version: "4.9.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
url: "https://pub.dev"
source: hosted
version: "10.0.9"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0
url: "https://pub.dev"
source: hosted
version: "6.0.0"
logging:
dependency: transitive
description:
name: logging
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
url: "https://pub.dev"
source: hosted
version: "1.3.0"
macros:
dependency: transitive
description:
name: macros
sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656"
url: "https://pub.dev"
source: hosted
version: "0.1.3-main.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev"
source: hosted
version: "0.12.17"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
version: "1.16.0"
mime:
dependency: transitive
description:
name: mime
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
package_config:
dependency: transitive
description:
name: package_config
sha256: f096c55ebb7deb7e384101542bfba8c52696c1b56fca2eb62827989ef2353bbc
url: "https://pub.dev"
source: hosted
version: "2.2.0"
path:
dependency: transitive
description:
name: path
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
path_provider:
dependency: transitive
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: "3b4c1fc3aa55ddc9cd4aa6759984330d5c8e66aa7702a6223c61540dc6380c37"
url: "https://pub.dev"
source: hosted
version: "2.2.19"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: "16eef174aacb07e09c351502740fa6254c165757638eba1e9116b0a781201bbd"
url: "https://pub.dev"
source: hosted
version: "2.4.2"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
url: "https://pub.dev"
source: hosted
version: "2.3.0"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: "1a97266a94f7350d30ae522c0af07890c70b8e62c71e8e3920d1db4d23c057d1"
url: "https://pub.dev"
source: hosted
version: "7.0.1"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
pool:
dependency: transitive
description:
name: pool
sha256: "978783255c543aa3586a1b3c21f6e9d720eb315376a915872c61ef8b5c20177d"
url: "https://pub.dev"
source: hosted
version: "1.5.2"
process:
dependency: transitive
description:
name: process
sha256: c6248e4526673988586e8c00bb22a49210c258dc91df5227d5da9748ecf79744
url: "https://pub.dev"
source: hosted
version: "5.0.5"
pub_semver:
dependency: transitive
description:
name: pub_semver
sha256: "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
pub_updater:
dependency: transitive
description:
name: pub_updater
sha256: "739a0161d73a6974c0675b864fb0cf5147305f7b077b7f03a58fa7a9ab3e7e7d"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
pubspec_parse:
dependency: transitive
description:
name: pubspec_parse
sha256: "0560ba233314abbed0a48a2956f7f022cce7c3e1e73df540277da7544cad4082"
url: "https://pub.dev"
source: hosted
version: "1.5.0"
shelf:
dependency: transitive
description:
name: shelf
sha256: e7dd780a7ffb623c57850b33f43309312fc863fb6aa3d276a754bb299839ef12
url: "https://pub.dev"
source: hosted
version: "1.4.2"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
sha256: "3632775c8e90d6c9712f883e633716432a27758216dfb61bd86a8321c0580925"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
source_gen:
dependency: transitive
description:
name: source_gen
sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832"
url: "https://pub.dev"
source: hosted
version: "1.5.0"
source_helper:
dependency: transitive
description:
name: source_helper
sha256: "86d247119aedce8e63f4751bd9626fc9613255935558447569ad42f9f5b48b3c"
url: "https://pub.dev"
source: hosted
version: "1.3.5"
source_span:
dependency: transitive
description:
name: source_span
sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
url: "https://pub.dev"
source: hosted
version: "1.10.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
url: "https://pub.dev"
source: hosted
version: "1.12.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
stream_transform:
dependency: transitive
description:
name: stream_transform
sha256: ad47125e588cfd37a9a7f86c7d6356dde8dfe89d071d293f80ca9e9273a33871
url: "https://pub.dev"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
url: "https://pub.dev"
source: hosted
version: "1.4.1"
swipe_refresh:
dependency: "direct main"
description:
name: swipe_refresh
sha256: "7f155dd2c370d128cd77f4d73cf8e477b0413268d8554639e4211a98abc98438"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
swipeable_tile:
dependency: "direct dev"
description:
name: swipeable_tile
sha256: "6312b59b14c5ff22bf91aafa64d7e74df5f2322cb206db4c34d9d9946e3e44d4"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
url: "https://pub.dev"
source: hosted
version: "1.2.2"
test_api:
dependency: transitive
description:
name: test_api
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev"
source: hosted
version: "0.7.4"
timing:
dependency: transitive
description:
name: timing
sha256: "62ee18aca144e4a9f29d212f5a4c6a053be252b895ab14b5821996cff4ed90fe"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
tint:
dependency: transitive
description:
name: tint
sha256: "9652d9a589f4536d5e392cf790263d120474f15da3cf1bee7f1fdb31b4de5f46"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
toggle_switch:
dependency: "direct dev"
description:
name: toggle_switch
sha256: dca04512d7c23ed320d6c5ede1211a404f177d54d353bf785b07d15546a86ce5
url: "https://pub.dev"
source: hosted
version: "2.3.0"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://pub.dev"
source: hosted
version: "1.4.0"
vector_graphics:
dependency: transitive
description:
name: vector_graphics
sha256: a4f059dc26fc8295b5921376600a194c4ec7d55e72f2fe4c7d2831e103d461e6
url: "https://pub.dev"
source: hosted
version: "1.1.19"
vector_graphics_codec:
dependency: transitive
description:
name: vector_graphics_codec
sha256: "99fd9fbd34d9f9a32efd7b6a6aae14125d8237b10403b422a6a6dfeac2806146"
url: "https://pub.dev"
source: hosted
version: "1.1.13"
vector_graphics_compiler:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: d354a7ec6931e6047785f4db12a1f61ec3d43b207fc0790f863818543f8ff0dc
url: "https://pub.dev"
source: hosted
version: "1.1.19"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
url: "https://pub.dev"
source: hosted
version: "15.0.0"
watcher:
dependency: transitive
description:
name: watcher
sha256: "1398c9f081a753f9226febe8900fce8f7d0a67163334e1c94a2438339d79d635"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
web:
dependency: transitive
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
web_socket:
dependency: transitive
description:
name: web_socket
sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8
url: "https://pub.dev"
source: hosted
version: "3.0.3"
win32:
dependency: transitive
description:
name: win32
sha256: d7cb55e04cd34096cd3a79b3330245f54cb96a370a1c27adb3c84b917de8b08e
url: "https://pub.dev"
source: hosted
version: "5.15.0"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
xml:
dependency: transitive
description:
name: xml
sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025"
url: "https://pub.dev"
source: hosted
version: "6.6.1"
yaml:
dependency: transitive
description:
name: yaml
sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce
url: "https://pub.dev"
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.8.1 <4.0.0"
flutter: ">=3.32.0"

36
pubspec.yaml Normal file
View File

@@ -0,0 +1,36 @@
name: Stocky
description: "Приложение для кладовщика."
publish_to: 'none'
version: 0.1.0
environment:
sdk: ^3.8.1
dependencies:
firebase_core: ^4.4.0
firebase_messaging: ^16.1.1
flutter:
sdk: flutter
flutter_advanced_avatar: ^1.5.2
flutterfire_cli: ^1.3.1
hugeicons: ^1.1.0
swipe_refresh: ^1.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints:
get:
toggle_switch:
hive:
hive_flutter:
dio:
extended_masked_text:
build_runner:
hive_generator:
swipeable_tile:
eva_icons_flutter:
flutter:
uses-material-design: true

BIN
web/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

BIN
web/icons/Icon-192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
web/icons/Icon-512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

38
web/index.html Normal file
View File

@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="flutter_stocky">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>flutter_stocky</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<script src="flutter_bootstrap.js" async></script>
</body>
</html>

35
web/manifest.json Normal file
View File

@@ -0,0 +1,35 @@
{
"name": "flutter_stocky",
"short_name": "flutter_stocky",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}

0
web_entrypoint.dart Normal file
View File

17
windows/.gitignore vendored Normal file
View File

@@ -0,0 +1,17 @@
flutter/ephemeral/
# Visual Studio user-specific files.
*.suo
*.user
*.userosscache
*.sln.docstates
# Visual Studio build-related files.
x64/
x86/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

108
windows/CMakeLists.txt Normal file
View File

@@ -0,0 +1,108 @@
# Project-level configuration.
cmake_minimum_required(VERSION 3.14)
project(flutter_stocky LANGUAGES CXX)
# The name of the executable created for the application. Change this to change
# the on-disk name of your application.
set(BINARY_NAME "flutter_stocky")
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
cmake_policy(VERSION 3.14...3.25)
# Define build configuration option.
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTICONFIG)
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
CACHE STRING "" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Flutter build mode" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Profile" "Release")
endif()
endif()
# Define settings for the Profile build mode.
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
# Use Unicode for all projects.
add_definitions(-DUNICODE -D_UNICODE)
# Compilation settings that should be applied to most targets.
#
# Be cautious about adding new options here, as plugins use this function by
# default. In most cases, you should add new options to specific targets instead
# of modifying this function.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_17)
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
target_compile_options(${TARGET} PRIVATE /EHsc)
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
endfunction()
# Flutter library and tool build rules.
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
add_subdirectory(${FLUTTER_MANAGED_DIR})
# Application build; see runner/CMakeLists.txt.
add_subdirectory("runner")
# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)
# === Installation ===
# Support files are copied into place next to the executable, so that it can
# run in place. This is done instead of making a separate bundle (as on Linux)
# so that building and running from within Visual Studio will work.
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
# Make the "install" step default, as it's required to run.
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
COMPONENT Runtime)
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
COMPONENT Runtime)
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
if(PLUGIN_BUNDLED_LIBRARIES)
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()
# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
install(CODE "
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
" COMPONENT Runtime)
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
# Install the AOT library on non-Debug builds only.
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
CONFIGURATIONS Profile;Release
COMPONENT Runtime)

View File

@@ -0,0 +1,109 @@
# This file controls Flutter-level build steps. It should not be edited.
cmake_minimum_required(VERSION 3.14)
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
# Configuration provided via flutter tool.
include(${EPHEMERAL_DIR}/generated_config.cmake)
# TODO: Move the rest of this into files in ephemeral. See
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()
# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
# Published to parent scope for install step.
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
list(APPEND FLUTTER_LIBRARY_HEADERS
"flutter_export.h"
"flutter_windows.h"
"flutter_messenger.h"
"flutter_plugin_registrar.h"
"flutter_texture_registrar.h"
)
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
add_library(flutter INTERFACE)
target_include_directories(flutter INTERFACE
"${EPHEMERAL_DIR}"
)
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
add_dependencies(flutter flutter_assemble)
# === Wrapper ===
list(APPEND CPP_WRAPPER_SOURCES_CORE
"core_implementations.cc"
"standard_codec.cc"
)
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
"plugin_registrar.cc"
)
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
list(APPEND CPP_WRAPPER_SOURCES_APP
"flutter_engine.cc"
"flutter_view_controller.cc"
)
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
# Wrapper sources needed for a plugin.
add_library(flutter_wrapper_plugin STATIC
${CPP_WRAPPER_SOURCES_CORE}
${CPP_WRAPPER_SOURCES_PLUGIN}
)
apply_standard_settings(flutter_wrapper_plugin)
set_target_properties(flutter_wrapper_plugin PROPERTIES
POSITION_INDEPENDENT_CODE ON)
set_target_properties(flutter_wrapper_plugin PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
target_include_directories(flutter_wrapper_plugin PUBLIC
"${WRAPPER_ROOT}/include"
)
add_dependencies(flutter_wrapper_plugin flutter_assemble)
# Wrapper sources needed for the runner.
add_library(flutter_wrapper_app STATIC
${CPP_WRAPPER_SOURCES_CORE}
${CPP_WRAPPER_SOURCES_APP}
)
apply_standard_settings(flutter_wrapper_app)
target_link_libraries(flutter_wrapper_app PUBLIC flutter)
target_include_directories(flutter_wrapper_app PUBLIC
"${WRAPPER_ROOT}/include"
)
add_dependencies(flutter_wrapper_app flutter_assemble)
# === Flutter tool backend ===
# _phony_ is a non-existent file to force this command to run every time,
# since currently there's no way to get a full input/output list from the
# flutter tool.
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
${CPP_WRAPPER_SOURCES_APP}
${PHONY_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
"${FLUTTER_LIBRARY}"
${FLUTTER_LIBRARY_HEADERS}
${CPP_WRAPPER_SOURCES_CORE}
${CPP_WRAPPER_SOURCES_PLUGIN}
${CPP_WRAPPER_SOURCES_APP}
)

View File

@@ -0,0 +1,14 @@
//
// Generated file. Do not edit.
//
// clang-format off
#include "generated_plugin_registrant.h"
#include <firebase_core/firebase_core_plugin_c_api.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
FirebaseCorePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
}

View File

@@ -0,0 +1,15 @@
//
// Generated file. Do not edit.
//
// clang-format off
#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_
#include <flutter/plugin_registry.h>
// Registers Flutter plugins.
void RegisterPlugins(flutter::PluginRegistry* registry);
#endif // GENERATED_PLUGIN_REGISTRANT_

View File

@@ -0,0 +1,24 @@
#
# Generated file, do not edit.
#
list(APPEND FLUTTER_PLUGIN_LIST
firebase_core
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)

View File

@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.14)
project(runner LANGUAGES CXX)
# Define the application target. To change its name, change BINARY_NAME in the
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
# work.
#
# Any new source files that you add to the application should be added here.
add_executable(${BINARY_NAME} WIN32
"flutter_window.cpp"
"main.cpp"
"utils.cpp"
"win32_window.cpp"
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
"Runner.rc"
"runner.exe.manifest"
)
# Apply the standard set of build settings. This can be removed for applications
# that need different build settings.
apply_standard_settings(${BINARY_NAME})
# Add preprocessor definitions for the build version.
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
# Disable Windows macros that collide with C++ standard library functions.
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
# Add dependency libraries and include directories. Add any application-specific
# dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)

121
windows/runner/Runner.rc Normal file
View File

@@ -0,0 +1,121 @@
// Microsoft Visual C++ generated resource script.
//
#pragma code_page(65001)
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_APP_ICON ICON "resources\\app_icon.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
#else
#define VERSION_AS_NUMBER 1,0,0,0
#endif
#if defined(FLUTTER_VERSION)
#define VERSION_AS_STRING FLUTTER_VERSION
#else
#define VERSION_AS_STRING "1.0.0"
#endif
VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_AS_NUMBER
PRODUCTVERSION VERSION_AS_NUMBER
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "com.example" "\0"
VALUE "FileDescription", "flutter_stocky" "\0"
VALUE "FileVersion", VERSION_AS_STRING "\0"
VALUE "InternalName", "flutter_stocky" "\0"
VALUE "LegalCopyright", "Copyright (C) 2025 com.example. All rights reserved." "\0"
VALUE "OriginalFilename", "flutter_stocky.exe" "\0"
VALUE "ProductName", "flutter_stocky" "\0"
VALUE "ProductVersion", VERSION_AS_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,71 @@
#include "flutter_window.h"
#include <optional>
#include "flutter/generated_plugin_registrant.h"
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
: project_(project) {}
FlutterWindow::~FlutterWindow() {}
bool FlutterWindow::OnCreate() {
if (!Win32Window::OnCreate()) {
return false;
}
RECT frame = GetClientArea();
// The size here must match the window dimensions to avoid unnecessary surface
// creation / destruction in the startup path.
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false;
}
RegisterPlugins(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow());
flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
});
// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();
return true;
}
void FlutterWindow::OnDestroy() {
if (flutter_controller_) {
flutter_controller_ = nullptr;
}
Win32Window::OnDestroy();
}
LRESULT
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_) {
std::optional<LRESULT> result =
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
lparam);
if (result) {
return *result;
}
}
switch (message) {
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
}
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
}

View File

@@ -0,0 +1,33 @@
#ifndef RUNNER_FLUTTER_WINDOW_H_
#define RUNNER_FLUTTER_WINDOW_H_
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <memory>
#include "win32_window.h"
// A window that does nothing but host a Flutter view.
class FlutterWindow : public Win32Window {
public:
// Creates a new FlutterWindow hosting a Flutter view running |project|.
explicit FlutterWindow(const flutter::DartProject& project);
virtual ~FlutterWindow();
protected:
// Win32Window:
bool OnCreate() override;
void OnDestroy() override;
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
LPARAM const lparam) noexcept override;
private:
// The project to run.
flutter::DartProject project_;
// The Flutter instance hosted by this window.
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
};
#endif // RUNNER_FLUTTER_WINDOW_H_

43
windows/runner/main.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <windows.h>
#include "flutter_window.h"
#include "utils.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.Create(L"flutter_stocky", origin, size)) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}

16
windows/runner/resource.h Normal file
View File

@@ -0,0 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Runner.rc
//
#define IDI_APP_ICON 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 and Windows 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

65
windows/runner/utils.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "utils.h"
#include <flutter_windows.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
#include <iostream>
void CreateAndAttachConsole() {
if (::AllocConsole()) {
FILE *unused;
if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
_dup2(_fileno(stdout), 1);
}
if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
_dup2(_fileno(stdout), 2);
}
std::ios::sync_with_stdio();
FlutterDesktopResyncOutputStreams();
}
}
std::vector<std::string> GetCommandLineArguments() {
// Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
int argc;
wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
if (argv == nullptr) {
return std::vector<std::string>();
}
std::vector<std::string> command_line_arguments;
// Skip the first argument as it's the binary name.
for (int i = 1; i < argc; i++) {
command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
}
::LocalFree(argv);
return command_line_arguments;
}
std::string Utf8FromUtf16(const wchar_t* utf16_string) {
if (utf16_string == nullptr) {
return std::string();
}
unsigned int target_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, nullptr, 0, nullptr, nullptr)
-1; // remove the trailing null character
int input_length = (int)wcslen(utf16_string);
std::string utf8_string;
if (target_length == 0 || target_length > utf8_string.max_size()) {
return utf8_string;
}
utf8_string.resize(target_length);
int converted_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
input_length, utf8_string.data(), target_length, nullptr, nullptr);
if (converted_length == 0) {
return std::string();
}
return utf8_string;
}

19
windows/runner/utils.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef RUNNER_UTILS_H_
#define RUNNER_UTILS_H_
#include <string>
#include <vector>
// Creates a console for the process, and redirects stdout and stderr to
// it for both the runner and the Flutter library.
void CreateAndAttachConsole();
// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
// encoded in UTF-8. Returns an empty std::string on failure.
std::string Utf8FromUtf16(const wchar_t* utf16_string);
// Gets the command line arguments passed in as a std::vector<std::string>,
// encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
std::vector<std::string> GetCommandLineArguments();
#endif // RUNNER_UTILS_H_

View File

@@ -0,0 +1,288 @@
#include "win32_window.h"
#include <dwmapi.h>
#include <flutter_windows.h>
#include "resource.h"
namespace {
/// Window attribute that enables dark mode window decorations.
///
/// Redefined in case the developer's machine has a Windows SDK older than
/// version 10.0.22000.0.
/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
/// Registry key for app theme preference.
///
/// A value of 0 indicates apps should use dark mode. A non-zero or missing
/// value indicates apps should use light mode.
constexpr const wchar_t kGetPreferredBrightnessRegKey[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme";
// The number of Win32Window objects that currently exist.
static int g_active_window_count = 0;
using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
// Scale helper to convert logical scaler values to physical using passed in
// scale factor
int Scale(int source, double scale_factor) {
return static_cast<int>(source * scale_factor);
}
// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
// This API is only needed for PerMonitor V1 awareness mode.
void EnableFullDpiSupportIfAvailable(HWND hwnd) {
HMODULE user32_module = LoadLibraryA("User32.dll");
if (!user32_module) {
return;
}
auto enable_non_client_dpi_scaling =
reinterpret_cast<EnableNonClientDpiScaling*>(
GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
if (enable_non_client_dpi_scaling != nullptr) {
enable_non_client_dpi_scaling(hwnd);
}
FreeLibrary(user32_module);
}
} // namespace
// Manages the Win32Window's window class registration.
class WindowClassRegistrar {
public:
~WindowClassRegistrar() = default;
// Returns the singleton registrar instance.
static WindowClassRegistrar* GetInstance() {
if (!instance_) {
instance_ = new WindowClassRegistrar();
}
return instance_;
}
// Returns the name of the window class, registering the class if it hasn't
// previously been registered.
const wchar_t* GetWindowClass();
// Unregisters the window class. Should only be called if there are no
// instances of the window.
void UnregisterWindowClass();
private:
WindowClassRegistrar() = default;
static WindowClassRegistrar* instance_;
bool class_registered_ = false;
};
WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
const wchar_t* WindowClassRegistrar::GetWindowClass() {
if (!class_registered_) {
WNDCLASS window_class{};
window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
window_class.lpszClassName = kWindowClassName;
window_class.style = CS_HREDRAW | CS_VREDRAW;
window_class.cbClsExtra = 0;
window_class.cbWndExtra = 0;
window_class.hInstance = GetModuleHandle(nullptr);
window_class.hIcon =
LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
window_class.hbrBackground = 0;
window_class.lpszMenuName = nullptr;
window_class.lpfnWndProc = Win32Window::WndProc;
RegisterClass(&window_class);
class_registered_ = true;
}
return kWindowClassName;
}
void WindowClassRegistrar::UnregisterWindowClass() {
UnregisterClass(kWindowClassName, nullptr);
class_registered_ = false;
}
Win32Window::Win32Window() {
++g_active_window_count;
}
Win32Window::~Win32Window() {
--g_active_window_count;
Destroy();
}
bool Win32Window::Create(const std::wstring& title,
const Point& origin,
const Size& size) {
Destroy();
const wchar_t* window_class =
WindowClassRegistrar::GetInstance()->GetWindowClass();
const POINT target_point = {static_cast<LONG>(origin.x),
static_cast<LONG>(origin.y)};
HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
double scale_factor = dpi / 96.0;
HWND window = CreateWindow(
window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
nullptr, nullptr, GetModuleHandle(nullptr), this);
if (!window) {
return false;
}
UpdateTheme(window);
return OnCreate();
}
bool Win32Window::Show() {
return ShowWindow(window_handle_, SW_SHOWNORMAL);
}
// static
LRESULT CALLBACK Win32Window::WndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
if (message == WM_NCCREATE) {
auto window_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
SetWindowLongPtr(window, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(window_struct->lpCreateParams));
auto that = static_cast<Win32Window*>(window_struct->lpCreateParams);
EnableFullDpiSupportIfAvailable(window);
that->window_handle_ = window;
} else if (Win32Window* that = GetThisFromHandle(window)) {
return that->MessageHandler(window, message, wparam, lparam);
}
return DefWindowProc(window, message, wparam, lparam);
}
LRESULT
Win32Window::MessageHandler(HWND hwnd,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
switch (message) {
case WM_DESTROY:
window_handle_ = nullptr;
Destroy();
if (quit_on_close_) {
PostQuitMessage(0);
}
return 0;
case WM_DPICHANGED: {
auto newRectSize = reinterpret_cast<RECT*>(lparam);
LONG newWidth = newRectSize->right - newRectSize->left;
LONG newHeight = newRectSize->bottom - newRectSize->top;
SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
return 0;
}
case WM_SIZE: {
RECT rect = GetClientArea();
if (child_content_ != nullptr) {
// Size and position the child window.
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, TRUE);
}
return 0;
}
case WM_ACTIVATE:
if (child_content_ != nullptr) {
SetFocus(child_content_);
}
return 0;
case WM_DWMCOLORIZATIONCOLORCHANGED:
UpdateTheme(hwnd);
return 0;
}
return DefWindowProc(window_handle_, message, wparam, lparam);
}
void Win32Window::Destroy() {
OnDestroy();
if (window_handle_) {
DestroyWindow(window_handle_);
window_handle_ = nullptr;
}
if (g_active_window_count == 0) {
WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
}
}
Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
return reinterpret_cast<Win32Window*>(
GetWindowLongPtr(window, GWLP_USERDATA));
}
void Win32Window::SetChildContent(HWND content) {
child_content_ = content;
SetParent(content, window_handle_);
RECT frame = GetClientArea();
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
frame.bottom - frame.top, true);
SetFocus(child_content_);
}
RECT Win32Window::GetClientArea() {
RECT frame;
GetClientRect(window_handle_, &frame);
return frame;
}
HWND Win32Window::GetHandle() {
return window_handle_;
}
void Win32Window::SetQuitOnClose(bool quit_on_close) {
quit_on_close_ = quit_on_close;
}
bool Win32Window::OnCreate() {
// No-op; provided for subclasses.
return true;
}
void Win32Window::OnDestroy() {
// No-op; provided for subclasses.
}
void Win32Window::UpdateTheme(HWND const window) {
DWORD light_mode;
DWORD light_mode_size = sizeof(light_mode);
LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
kGetPreferredBrightnessRegValue,
RRF_RT_REG_DWORD, nullptr, &light_mode,
&light_mode_size);
if (result == ERROR_SUCCESS) {
BOOL enable_dark_mode = light_mode == 0;
DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE,
&enable_dark_mode, sizeof(enable_dark_mode));
}
}

View File

@@ -0,0 +1,102 @@
#ifndef RUNNER_WIN32_WINDOW_H_
#define RUNNER_WIN32_WINDOW_H_
#include <windows.h>
#include <functional>
#include <memory>
#include <string>
// A class abstraction for a high DPI-aware Win32 Window. Intended to be
// inherited from by classes that wish to specialize with custom
// rendering and input handling
class Win32Window {
public:
struct Point {
unsigned int x;
unsigned int y;
Point(unsigned int x, unsigned int y) : x(x), y(y) {}
};
struct Size {
unsigned int width;
unsigned int height;
Size(unsigned int width, unsigned int height)
: width(width), height(height) {}
};
Win32Window();
virtual ~Win32Window();
// Creates a win32 window with |title| that is positioned and sized using
// |origin| and |size|. New windows are created on the default monitor. Window
// sizes are specified to the OS in physical pixels, hence to ensure a
// consistent size this function will scale the inputted width and height as
// as appropriate for the default monitor. The window is invisible until
// |Show| is called. Returns true if the window was created successfully.
bool Create(const std::wstring& title, const Point& origin, const Size& size);
// Show the current window. Returns true if the window was successfully shown.
bool Show();
// Release OS resources associated with window.
void Destroy();
// Inserts |content| into the window tree.
void SetChildContent(HWND content);
// Returns the backing Window handle to enable clients to set icon and other
// window properties. Returns nullptr if the window has been destroyed.
HWND GetHandle();
// If true, closing this window will quit the application.
void SetQuitOnClose(bool quit_on_close);
// Return a RECT representing the bounds of the current client area.
RECT GetClientArea();
protected:
// Processes and route salient window messages for mouse handling,
// size change and DPI. Delegates handling of these to member overloads that
// inheriting classes can handle.
virtual LRESULT MessageHandler(HWND window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept;
// Called when CreateAndShow is called, allowing subclass window-related
// setup. Subclasses should return false if setup fails.
virtual bool OnCreate();
// Called when Destroy is called.
virtual void OnDestroy();
private:
friend class WindowClassRegistrar;
// OS callback called by message pump. Handles the WM_NCCREATE message which
// is passed when the non-client area is being created and enables automatic
// non-client DPI scaling so that the non-client area automatically
// responds to changes in DPI. All other messages are handled by
// MessageHandler.
static LRESULT CALLBACK WndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept;
// Retrieves a class instance pointer for |window|
static Win32Window* GetThisFromHandle(HWND const window) noexcept;
// Update the window frame's theme to match the system theme.
static void UpdateTheme(HWND const window);
bool quit_on_close_ = false;
// window handle for top level window.
HWND window_handle_ = nullptr;
// window handle for hosted content.
HWND child_content_ = nullptr;
};
#endif // RUNNER_WIN32_WINDOW_H_