Создание пакета

This commit is contained in:
PROF25-FINAL 2025-05-27 10:08:54 +03:00
parent 7c9433a26d
commit 0c06f60ab1
13 changed files with 280 additions and 1 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

View File

@ -1 +1,39 @@
# matule_query <!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

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

11
lib/matule_query.dart Normal file
View File

@ -0,0 +1,11 @@
library;
export "src/data/models/auth_model.dart";
export "src/data/models/metadata_model.dart";
export "src/data/repository/client.dart";
export "src/data/repository/repository.dart";
export "src/domain/services/query_helper.dart";
export "src/domain/use_cases/base_use_case.dart";

View File

@ -0,0 +1,12 @@
import 'package:matule_query/matule_query.dart';
class AuthModel {
final String token;
final MetadataModel record;
AuthModel({required this.token, required this.record});
AuthModel.fromJSON(Map<String, dynamic> json)
: token = json["token"],
record = MetadataModel.fromJSON(json["record"]);
}

View File

@ -0,0 +1,28 @@
class MetadataModel {
final String email;
final String dateBirthday;
final String firstName;
final String gender;
final String id;
final String lastName;
final String secondName;
MetadataModel({
required this.email,
required this.dateBirthday,
required this.firstName,
required this.gender,
required this.id,
required this.lastName,
required this.secondName,
});
MetadataModel.fromJSON(Map<String, dynamic> json)
: email = json["email"],
dateBirthday = json["dateBirthday"],
firstName = json["firstname"],
gender = json["gender"],
id = json["id"],
lastName = json["lastname"],
secondName = json["secondname"];
}

View File

@ -0,0 +1,16 @@
import 'package:dio/dio.dart';
import '../../../matule_query.dart';
class Client extends Repository {
@override
String get apiUrl => "https://api.matule.ru/api";
AuthModel? _authModel;
Options get options => Options(
headers: (_authModel != null)
? {"Authorization": "Bearer ${_authModel!.token}"}
: null,
);
}

View File

@ -0,0 +1,6 @@
import 'package:dio/dio.dart';
abstract class Repository {
final Dio dio = Dio();
abstract final String apiUrl;
}

View File

@ -0,0 +1,22 @@
class QueryHelper {
final Function() startLoading;
final Function() endLoading;
QueryHelper({required this.startLoading, required this.endLoading});
Future<void> request<ResponseT>(
Future<ResponseT> Function() request,
void Function(ResponseT) onResponse,
void Function(Exception) onError,
) async {
try {
startLoading();
ResponseT response = await request();
endLoading();
onResponse(response);
} on Exception catch (e) {
endLoading();
onError(e);
}
}
}

View File

@ -0,0 +1,16 @@
import 'package:matule_query/matule_query.dart';
class BaseUseCase {
final Function() startLoading;
final Function() endLoading;
final Function(Object?) onResponse;
final Function(Exception) onError;
final QueryHelper helper;
BaseUseCase({
required this.startLoading,
required this.endLoading,
required this.onResponse,
required this.onError,
}) : helper = QueryHelper(startLoading: startLoading, endLoading: endLoading);
}

58
pubspec.yaml Normal file
View File

@ -0,0 +1,58 @@
name: matule_query
description: "A new Flutter package project."
version: 0.0.1
publish_to: "none"
environment:
sdk: ^3.8.0
flutter: ">=1.17.0"
dependencies:
connectivity_plus: ^6.1.4
dio: ^5.8.0+1
intl: ^0.20.2
flutter:
sdk: flutter
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:
uses-material-design: true
# 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

View File

@ -0,0 +1,27 @@
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import "package:dio/dio.dart";
import 'package:matule_query/matule_query.dart';
String get testString => DateTime.now().millisecondsSinceEpoch.toString();
Options get options => Options(headers: {});
BaseUseCase useCase = BaseUseCase(
startLoading: () {},
endLoading: () {},
onResponse: (Object? obj) {
stdout.writeln(obj.toString());
assert(true);
},
onError: (Exception e) {
fail(e.toString());
},
);
void main() {
group("Query", () {
test("Authorization", () async {});
});
}