Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
base_data_channel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PublicSource
base_data_channel
Commits
d67e49e3
Commit
d67e49e3
authored
Apr 07, 2023
by
tongzifang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add common upload
parent
8e416f72
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
352 additions
and
0 deletions
+352
-0
pubspec.lock
example/pubspec.lock
+24
-0
common_up_img_entity.dart
lib/data/common_up_img_entity.dart
+41
-0
json_convert_content.dart
lib/generated/json/base/json_convert_content.dart
+114
-0
json_field.dart
lib/generated/json/base/json_field.dart
+25
-0
common_up_img_entity.g.dart
lib/generated/json/common_up_img_entity.g.dart
+57
-0
common_client.dart
lib/request/common_client.dart
+22
-0
common_client.g.dart
lib/request/common_client.g.dart
+65
-0
pubspec.yaml
pubspec.yaml
+4
-0
No files found.
example/pubspec.lock
View file @
d67e49e3
...
...
@@ -198,6 +198,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.3.0"
flutter_easyloading:
dependency: transitive
description:
name: flutter_easyloading
sha256: ba21a3c883544e582f9cc455a4a0907556714e1e9cf0eababfcb600da191d17c
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.5"
flutter_lints:
dependency: "direct dev"
description:
...
...
@@ -214,6 +222,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.9"
flutter_spinkit:
dependency: transitive
description:
name: flutter_spinkit
sha256: "77a2117c0517ff909221f3160b8eb20052ab5216107581168af574ac1f05dff8"
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.1.0"
flutter_test:
dependency: "direct dev"
description: flutter
...
...
@@ -224,6 +240,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: transitive
description:
name: fluttertoast
sha256: "2f9c4d3f4836421f7067a28f8939814597b27614e021da9d63e5d3fb6e212d25"
url: "https://pub.flutter-io.cn"
source: hosted
version: "8.2.1"
glob:
dependency: transitive
description:
...
...
lib/data/common_up_img_entity.dart
0 → 100644
View file @
d67e49e3
import
'package:base_data_channel/generated/json/base/json_field.dart'
;
import
'package:base_data_channel/generated/json/common_up_img_entity.g.dart'
;
import
'dart:convert'
;
@JsonSerializable
()
class
CommonUpImgEntity
{
String
?
status
;
String
?
code
;
String
?
message
;
CommonUpImgData
?
data
;
CommonUpImgEntity
();
factory
CommonUpImgEntity
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
$CommonUpImgEntityFromJson
(
json
);
Map
<
String
,
dynamic
>
toJson
()
=>
$CommonUpImgEntityToJson
(
this
);
@override
String
toString
()
{
return
jsonEncode
(
this
);
}
}
@JsonSerializable
()
class
CommonUpImgData
{
String
?
url
;
String
?
name
;
@JSONField
(
name:
"path_name"
)
String
?
pathName
;
CommonUpImgData
();
factory
CommonUpImgData
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
$CommonUpImgDataFromJson
(
json
);
Map
<
String
,
dynamic
>
toJson
()
=>
$CommonUpImgDataToJson
(
this
);
@override
String
toString
()
{
return
jsonEncode
(
this
);
}
}
\ No newline at end of file
lib/generated/json/base/json_convert_content.dart
0 → 100644
View file @
d67e49e3
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: camel_case_types
// ignore_for_file: prefer_single_quotes
// This file is automatically generated. DO NOT EDIT, all your changes would be lost.
import
'package:flutter/material.dart'
show
debugPrint
;
import
'package:base_data_channel/data/common_up_img_entity.dart'
;
JsonConvert
jsonConvert
=
JsonConvert
();
typedef
JsonConvertFunction
<
T
>
=
T
Function
(
Map
<
String
,
dynamic
>
json
);
typedef
EnumConvertFunction
<
T
>
=
T
Function
(
String
value
);
class
JsonConvert
{
static
final
Map
<
String
,
JsonConvertFunction
>
convertFuncMap
=
{
(
CommonUpImgEntity
).
toString
():
CommonUpImgEntity
.
fromJson
,
(
CommonUpImgData
).
toString
():
CommonUpImgData
.
fromJson
,
};
T
?
convert
<
T
>(
dynamic
value
,
{
EnumConvertFunction
?
enumConvert
})
{
if
(
value
==
null
)
{
return
null
;
}
if
(
value
is
T
)
{
return
value
;
}
try
{
return
_asT
<
T
>(
value
,
enumConvert:
enumConvert
);
}
catch
(
e
,
stackTrace
)
{
debugPrint
(
'asT<
$T
>
$e
$stackTrace
'
);
return
null
;
}
}
List
<
T
?>?
convertList
<
T
>(
List
<
dynamic
>?
value
,
{
EnumConvertFunction
?
enumConvert
})
{
if
(
value
==
null
)
{
return
null
;
}
try
{
return
value
.
map
((
dynamic
e
)
=>
_asT
<
T
>(
e
,
enumConvert:
enumConvert
)).
toList
();
}
catch
(
e
,
stackTrace
)
{
debugPrint
(
'asT<
$T
>
$e
$stackTrace
'
);
return
<
T
>[];
}
}
List
<
T
>?
convertListNotNull
<
T
>(
dynamic
value
,
{
EnumConvertFunction
?
enumConvert
})
{
if
(
value
==
null
)
{
return
null
;
}
try
{
return
(
value
as
List
<
dynamic
>).
map
((
dynamic
e
)
=>
_asT
<
T
>(
e
,
enumConvert:
enumConvert
)!).
toList
();
}
catch
(
e
,
stackTrace
)
{
debugPrint
(
'asT<
$T
>
$e
$stackTrace
'
);
return
<
T
>[];
}
}
T
?
_asT
<
T
extends
Object
?>(
dynamic
value
,
{
EnumConvertFunction
?
enumConvert
})
{
final
String
type
=
T
.
toString
();
final
String
valueS
=
value
.
toString
();
if
(
enumConvert
!=
null
)
{
return
enumConvert
(
valueS
)
as
T
;
}
else
if
(
type
==
"String"
)
{
return
valueS
as
T
;
}
else
if
(
type
==
"int"
)
{
final
int
?
intValue
=
int
.
tryParse
(
valueS
);
if
(
intValue
==
null
)
{
return
double
.
tryParse
(
valueS
)?.
toInt
()
as
T
?;
}
else
{
return
intValue
as
T
;
}
}
else
if
(
type
==
"double"
)
{
return
double
.
parse
(
valueS
)
as
T
;
}
else
if
(
type
==
"DateTime"
)
{
return
DateTime
.
parse
(
valueS
)
as
T
;
}
else
if
(
type
==
"bool"
)
{
if
(
valueS
==
'0'
||
valueS
==
'1'
)
{
return
(
valueS
==
'1'
)
as
T
;
}
return
(
valueS
==
'true'
)
as
T
;
}
else
if
(
type
==
"Map"
||
type
.
startsWith
(
"Map<"
))
{
return
value
as
T
;
}
else
{
if
(
convertFuncMap
.
containsKey
(
type
))
{
return
convertFuncMap
[
type
]!(
Map
<
String
,
dynamic
>.
from
(
value
))
as
T
;
}
else
{
throw
UnimplementedError
(
'
$type
unimplemented'
);
}
}
}
//list is returned by type
static
M
?
_getListChildType
<
M
>(
List
<
Map
<
String
,
dynamic
>>
data
)
{
if
(<
CommonUpImgEntity
>[]
is
M
){
return
data
.
map
<
CommonUpImgEntity
>((
Map
<
String
,
dynamic
>
e
)
=>
CommonUpImgEntity
.
fromJson
(
e
)).
toList
()
as
M
;
}
if
(<
CommonUpImgData
>[]
is
M
){
return
data
.
map
<
CommonUpImgData
>((
Map
<
String
,
dynamic
>
e
)
=>
CommonUpImgData
.
fromJson
(
e
)).
toList
()
as
M
;
}
debugPrint
(
"
${M.toString()}
not found"
);
return
null
;
}
static
M
?
fromJsonAsT
<
M
>(
dynamic
json
)
{
if
(
json
is
List
)
{
return
_getListChildType
<
M
>(
json
.
map
((
e
)
=>
e
as
Map
<
String
,
dynamic
>).
toList
());
}
else
{
return
jsonConvert
.
convert
<
M
>(
json
);
}
}
}
\ No newline at end of file
lib/generated/json/base/json_field.dart
0 → 100644
View file @
d67e49e3
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: camel_case_types
// ignore_for_file: prefer_single_quotes
// This file is automatically generated. DO NOT EDIT, all your changes would be lost.
class
JsonSerializable
{
const
JsonSerializable
();
}
class
JSONField
{
//Specify the parse field name
final
String
?
name
;
//Whether to participate in toJson
final
bool
?
serialize
;
//Whether to participate in fromMap
final
bool
?
deserialize
;
//Enumeration or not
final
bool
?
isEnum
;
const
JSONField
({
this
.
name
,
this
.
serialize
,
this
.
deserialize
,
this
.
isEnum
});
}
lib/generated/json/common_up_img_entity.g.dart
0 → 100644
View file @
d67e49e3
import
'package:base_data_channel/generated/json/base/json_convert_content.dart'
;
import
'package:base_data_channel/data/common_up_img_entity.dart'
;
CommonUpImgEntity
$CommonUpImgEntityFromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
CommonUpImgEntity
commonUpImgEntity
=
CommonUpImgEntity
();
final
String
?
status
=
jsonConvert
.
convert
<
String
>(
json
[
'status'
]);
if
(
status
!=
null
)
{
commonUpImgEntity
.
status
=
status
;
}
final
String
?
code
=
jsonConvert
.
convert
<
String
>(
json
[
'code'
]);
if
(
code
!=
null
)
{
commonUpImgEntity
.
code
=
code
;
}
final
String
?
message
=
jsonConvert
.
convert
<
String
>(
json
[
'message'
]);
if
(
message
!=
null
)
{
commonUpImgEntity
.
message
=
message
;
}
final
CommonUpImgData
?
data
=
jsonConvert
.
convert
<
CommonUpImgData
>(
json
[
'data'
]);
if
(
data
!=
null
)
{
commonUpImgEntity
.
data
=
data
;
}
return
commonUpImgEntity
;
}
Map
<
String
,
dynamic
>
$CommonUpImgEntityToJson
(
CommonUpImgEntity
entity
)
{
final
Map
<
String
,
dynamic
>
data
=
<
String
,
dynamic
>{};
data
[
'status'
]
=
entity
.
status
;
data
[
'code'
]
=
entity
.
code
;
data
[
'message'
]
=
entity
.
message
;
data
[
'data'
]
=
entity
.
data
?.
toJson
();
return
data
;
}
CommonUpImgData
$CommonUpImgDataFromJson
(
Map
<
String
,
dynamic
>
json
)
{
final
CommonUpImgData
commonUpImgData
=
CommonUpImgData
();
final
String
?
url
=
jsonConvert
.
convert
<
String
>(
json
[
'url'
]);
if
(
url
!=
null
)
{
commonUpImgData
.
url
=
url
;
}
final
String
?
name
=
jsonConvert
.
convert
<
String
>(
json
[
'name'
]);
if
(
name
!=
null
)
{
commonUpImgData
.
name
=
name
;
}
final
String
?
pathName
=
jsonConvert
.
convert
<
String
>(
json
[
'path_name'
]);
if
(
pathName
!=
null
)
{
commonUpImgData
.
pathName
=
pathName
;
}
return
commonUpImgData
;
}
Map
<
String
,
dynamic
>
$CommonUpImgDataToJson
(
CommonUpImgData
entity
)
{
final
Map
<
String
,
dynamic
>
data
=
<
String
,
dynamic
>{};
data
[
'url'
]
=
entity
.
url
;
data
[
'name'
]
=
entity
.
name
;
data
[
'path_name'
]
=
entity
.
pathName
;
return
data
;
}
\ No newline at end of file
lib/request/common_client.dart
0 → 100644
View file @
d67e49e3
import
'dart:io'
;
import
'package:base_data_channel/http/basedio.dart'
;
import
'package:dio/dio.dart'
;
import
'package:retrofit/retrofit.dart'
;
import
'../data/common_up_img_entity.dart'
;
part
'common_client.g.dart'
;
@RestApi
()
abstract
class
CommonClient
{
factory
CommonClient
({
Dio
?
dio
,
String
?
baseUrl
})
{
dio
=
BaseDio
.
getInstance
()!.
getDio
();
return
_CommonClient
(
dio
,
baseUrl:
baseUrl
);
}
@POST
(
"/coroutine/upload/image/index"
)
@MultiPart
()
Future
<
CommonUpImgEntity
>
commonUpFile
(
@Part
(
name:
"image"
,
contentType:
'image/jpeg'
)
File
file
);
}
lib/request/common_client.g.dart
0 → 100644
View file @
d67e49e3
// GENERATED CODE - DO NOT MODIFY BY HAND
part of
'common_client.dart'
;
// **************************************************************************
// RetrofitGenerator
// **************************************************************************
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers
class
_CommonClient
implements
CommonClient
{
_CommonClient
(
this
.
_dio
,
{
this
.
baseUrl
,
});
final
Dio
_dio
;
String
?
baseUrl
;
@override
Future
<
CommonUpImgEntity
>
commonUpFile
(
file
)
async
{
const
_extra
=
<
String
,
dynamic
>{};
final
queryParameters
=
<
String
,
dynamic
>{};
final
_headers
=
<
String
,
dynamic
>{};
final
_data
=
FormData
();
_data
.
files
.
add
(
MapEntry
(
'image'
,
MultipartFile
.
fromFileSync
(
file
.
path
,
filename:
file
.
path
.
split
(
Platform
.
pathSeparator
).
last
,
contentType:
MediaType
.
parse
(
'image/jpeg'
),
),
));
final
_result
=
await
_dio
.
fetch
<
Map
<
String
,
dynamic
>>(
_setStreamType
<
CommonUpImgEntity
>(
Options
(
method:
'POST'
,
headers:
_headers
,
extra:
_extra
,
contentType:
'multipart/form-data'
,
)
.
compose
(
_dio
.
options
,
'/coroutine/upload/image/index'
,
queryParameters:
queryParameters
,
data:
_data
,
)
.
copyWith
(
baseUrl:
baseUrl
??
_dio
.
options
.
baseUrl
)));
final
value
=
CommonUpImgEntity
.
fromJson
(
_result
.
data
!);
return
value
;
}
RequestOptions
_setStreamType
<
T
>(
RequestOptions
requestOptions
)
{
if
(
T
!=
dynamic
&&
!(
requestOptions
.
responseType
==
ResponseType
.
bytes
||
requestOptions
.
responseType
==
ResponseType
.
stream
))
{
if
(
T
==
String
)
{
requestOptions
.
responseType
=
ResponseType
.
plain
;
}
else
{
requestOptions
.
responseType
=
ResponseType
.
json
;
}
}
return
requestOptions
;
}
}
pubspec.yaml
View file @
d67e49e3
...
...
@@ -9,6 +9,8 @@ dev_dependencies:
flutter_test
:
sdk
:
flutter
flutter_lints
:
^2.0.0
retrofit_generator
:
'
>=6.0.0
<7.0.0'
build_runner
:
'
>=2.3.0
<4.0.0'
flutter
:
plugin
:
platforms
:
...
...
@@ -41,6 +43,8 @@ dependencies:
sp_util
:
^2.0.3
dio
:
^5.1.1
retrofit
:
^4.0.1
fluttertoast
:
^8.2.1
flutter_easyloading
:
^3.0.5
flutter_boost
:
git
:
url
:
'
https://github.com/alibaba/flutter_boost.git'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment