#sprint-1

This commit is contained in:
User3 2025-05-27 09:39:48 +03:00
parent 80f169acff
commit 84eb5b6773
11 changed files with 201 additions and 0 deletions

31
.gitignore vendored Normal file
View File

@ -0,0 +1,31 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
build/

10
.metadata Normal file
View File

@ -0,0 +1,10 @@
# 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: "be698c48a6750c8cb8e61c740ca9991bb947aba2"
channel: "stable"
project_type: package

3
CHANGELOG.md Normal file
View File

@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

1
LICENSE Normal file
View File

@ -0,0 +1 @@
TODO: Add your license here.

4
analysis_options.yaml Normal file
View File

@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

36
lib/apis/auth.dart Normal file
View File

@ -0,0 +1,36 @@
import 'package:dio/dio.dart';
import 'package:server/constants.dart';
import 'package:server/server.dart';
class Auth {
String lastError = '';
login(String email, String password) async {
try {
final response = api.post(
'/collections/users/auth-with-password',
data: {identity: email, password: password},
);
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
} else {
lastError = e.response!.data['message'];
}
}
}
register(String email, String password) async {
try {
final response = api.post(
'/collections/users/auth-with-password',
data: {identity: email, password: password},
);
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
} else {
lastError = e.response!.data['message'];
}
}
}
}

47
lib/client.dart Normal file
View File

@ -0,0 +1,47 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dio/dio.dart';
import 'package:server/constants.dart';
import 'package:shared_preferences/shared_preferences.dart';
final api = Dio(options);
final options = BaseOptions(baseUrl: 'https://api.matule.ru/api/');
initConnectivityChecker() async {
api.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
final connectivityResult = await Connectivity().checkConnectivity();
if (connectivityResult.isEmpty ||
connectivityResult.contains(ConnectivityResult.none)) {
return handler.reject(
DioException(
requestOptions: options,
error: 'У вас нет интернета',
type: DioExceptionType.connectionError,
),
);
} else {
return handler.next(options);
}
},
),
);
}
getLocalStorageInstance() async {
final prefs = await SharedPreferences.getInstance();
return prefs;
}
getToken() async {
final prefs = await getLocalStorageInstance();
if (prefs.containsKey(token)) {
return prefs.get(token);
}
}
setToken(value) async {
final prefs = await getLocalStorageInstance();
prefs.setString(token, value);
}

4
lib/constants.dart Normal file
View File

@ -0,0 +1,4 @@
const token = "token";
const identity = 'identity';
const password = 'password';

3
lib/server.dart Normal file
View File

@ -0,0 +1,3 @@
library server;
export 'client.dart';

57
pubspec.yaml Normal file
View File

@ -0,0 +1,57 @@
name: server
description: "A new Flutter package project."
version: 0.0.1
homepage:
environment:
sdk: ^3.8.0
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
dio: ^5.8.0+1
connectivity_plus: ^6.1.4
shared_preferences: ^2.5.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package

5
test/server_test.dart Normal file
View File

@ -0,0 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
void main() {
test('adds one to input values', () {});
}