Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xxapp-statistical
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
flutter-plugin
xxapp-statistical
Commits
3c36ecd6
Commit
3c36ecd6
authored
Oct 15, 2021
by
汪林玲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
null-safety
parent
8bfeb188
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
56 deletions
+39
-56
lib/repository/datareport_repository.dart
lib/repository/datareport_repository.dart
+2
-5
lib/repository/impl/datareport_repository_impl.dart
lib/repository/impl/datareport_repository_impl.dart
+3
-5
lib/src/entity/datareport_entity.dart
lib/src/entity/datareport_entity.dart
+1
-3
lib/src/sql/Sqlite3Helper.dart
lib/src/sql/Sqlite3Helper.dart
+11
-12
lib/src/statistical.dart
lib/src/statistical.dart
+9
-10
lib/src/xxstatistical.dart
lib/src/xxstatistical.dart
+3
-5
lib/tracker/exposure_widget.dart
lib/tracker/exposure_widget.dart
+9
-9
pubspec.yaml
pubspec.yaml
+1
-1
test/xxapp_statistical_test.dart
test/xxapp_statistical_test.dart
+0
-6
No files found.
lib/repository/datareport_repository.dart
View file @
3c36ecd6
import
'package:flutter/foundation.dart'
;
import
'impl/datareport_repository_impl.dart'
;
abstract
class
DatareportRepository
{
///
/// 获取单例
///
static
DatareportRepository
create
()
{
static
DatareportRepository
?
create
()
{
return
DatareportRepositoryImpl
.
get
();
}
...
...
@@ -15,6 +12,6 @@ abstract class DatareportRepository {
/// 数据上报接口
/// [list] 待上报的数据
///
Future
<
dynamic
>
dataReport
({
@
required
List
<
dynamic
>
list
});
Future
<
dynamic
>
dataReport
({
required
List
<
dynamic
>
list
});
}
\ No newline at end of file
lib/repository/impl/datareport_repository_impl.dart
View file @
3c36ecd6
import
'package:base_repository/base_repository.dart'
;
import
'package:flutter/foundation.dart'
;
import
'../datareport_repository.dart'
;
class
DatareportRepositoryImpl
extends
DatareportRepository
{
DatareportRepositoryImpl
.
_
();
static
DatareportRepositoryImpl
_instance
;
static
DatareportRepositoryImpl
?
_instance
;
static
DatareportRepositoryImpl
get
()
{
static
DatareportRepositoryImpl
?
get
()
{
if
(
_instance
==
null
)
{
_instance
=
DatareportRepositoryImpl
.
_
();
}
...
...
@@ -17,7 +15,7 @@ class DatareportRepositoryImpl extends DatareportRepository{
}
@override
Future
dataReport
({
@
required
List
<
dynamic
>
list
})
async
{
Future
dataReport
({
required
List
<
dynamic
>
list
})
async
{
Options
options
=
Options
(
headers:
{
'base_url'
:
'v6'
});
dynamic
result
=
await
DSDioUtil
.
getInstance
().
post
(
'/drp.send'
,
...
...
lib/src/entity/datareport_entity.dart
View file @
3c36ecd6
import
'package:flutter/material.dart'
;
///
/// 数据上报实体类
/// id、数据的自增id,如优惠券在数据库对应的id
...
...
@@ -19,5 +17,5 @@ class DataReportEntity {
/// [type] 数据类型:1信息流 2宣传口 3搜索结果 4优惠券 5活动配置
/// [amount] 点击或曝光的次数
///
DataReportEntity
({
@
required
this
.
id
,
this
.
event
=
2
,
this
.
type
=
1
,
this
.
amount
=
1
});
DataReportEntity
({
required
this
.
id
,
this
.
event
=
2
,
this
.
type
=
1
,
this
.
amount
=
1
});
}
\ No newline at end of file
lib/src/sql/Sqlite3Helper.dart
View file @
3c36ecd6
import
'package:flutter/material.dart'
;
import
'dart:async'
;
import
'package:path/path.dart'
;
import
'package:sqflite/sqflite.dart'
;
...
...
@@ -8,21 +7,21 @@ class Sqlite3Helper {
Sqlite3Helper
.
_
();
static
Sqlite3Helper
_instance
;
static
Sqlite3Helper
?
_instance
;
static
Sqlite3Helper
create
()
{
static
Sqlite3Helper
?
create
()
{
if
(
_instance
==
null
)
{
_instance
=
Sqlite3Helper
.
_
();
}
return
_instance
;
}
static
Future
<
Database
>
database
;
static
Future
<
Database
>
?
database
;
///
/// 初始化数据库
///
Future
<
int
>
init
()
async
{
Future
<
int
?
>
init
()
async
{
database
=
openDatabase
(
join
(
await
getDatabasesPath
(),
'xx_database.db'
),
onCreate:
(
db
,
version
)
{
...
...
@@ -41,9 +40,9 @@ class Sqlite3Helper {
///
/// 添加数据
///
void
add
({
@required
String
id
,
int
event
,
int
type
,
int
amount
=
1
})
async
{
void
add
({
required
String
id
,
int
?
event
,
int
?
type
,
int
amount
=
1
})
async
{
if
(
database
!=
null
){
final
db
=
await
database
;
final
db
=
await
database
!
;
String
sql
=
'INSERT INTO Statistical(id,event,type,amount) VALUES(?,?,?,?)'
;
await
db
.
execute
(
sql
,[
id
,
event
,
type
,
amount
]);
}
...
...
@@ -54,7 +53,7 @@ class Sqlite3Helper {
///
Future
<
List
<
Map
<
String
,
dynamic
>>>
query
()
async
{
if
(
database
!=
null
){
final
db
=
await
database
;
final
db
=
await
database
!
;
String
sql
=
'select id,event,type,COUNT(amount) as amount FROM Statistical GROUP BY id,event,type'
;
List
<
Map
<
String
,
dynamic
>>
results
=
await
db
.
rawQuery
(
sql
);
return
results
;
...
...
@@ -65,12 +64,12 @@ class Sqlite3Helper {
///
/// 查询数据库记录了多少条数据
///
Future
<
int
>
queryCount
()
async
{
Future
<
int
?
>
queryCount
()
async
{
if
(
database
!=
null
){
final
db
=
await
database
;
final
db
=
await
database
!
;
String
sql
=
'select COUNT(*) as amount FROM Statistical'
;
final
List
<
Map
<
String
,
dynamic
>>
maps
=
await
db
.
rawQuery
(
sql
);
if
(
maps
!=
null
&&
maps
.
length
>
0
){
if
(
maps
.
length
>
0
){
Map
<
String
,
dynamic
>
data
=
maps
[
0
];
if
(
data
[
'amount'
]
is
int
){
return
data
[
'amount'
];
...
...
@@ -85,7 +84,7 @@ class Sqlite3Helper {
///
Future
<
int
>
deleteAll
()
async
{
if
(
database
!=
null
){
final
db
=
await
database
;
final
db
=
await
database
!
;
int
number
=
await
db
.
delete
(
'Statistical'
);
return
number
;
}
...
...
lib/src/statistical.dart
View file @
3c36ecd6
import
'package:flutter/foundation.dart'
;
import
'package:xxstatistical/repository/datareport_repository.dart'
;
import
'package:xxstatistical/src/entity/datareport_entity.dart'
;
import
'package:xxstatistical/src/sql/Sqlite3Helper.dart'
;
...
...
@@ -7,9 +6,9 @@ import 'package:xxstatistical/src/sql/Sqlite3Helper.dart';
class
Statistical
{
Statistical
.
_
();
static
Statistical
_instance
;
static
Statistical
?
_instance
;
static
Statistical
create
()
{
static
Statistical
?
create
()
{
if
(
_instance
==
null
)
{
_instance
=
Statistical
.
_
();
}
...
...
@@ -30,8 +29,8 @@ class Statistical {
///
Future
<
Null
>
init
({
int
cachesMax
=
50
})
async
{
this
.
_cachesMax
=
cachesMax
;
int
amount
=
await
Sqlite3Helper
.
create
()
.
init
();
_cachesNumber
=
amount
;
int
?
amount
=
await
Sqlite3Helper
.
create
()!
.
init
();
_cachesNumber
=
amount
??
0
;
if
(
_cachesNumber
>=
10
){
this
.
_startUploadData
();
}
...
...
@@ -41,10 +40,10 @@ class Statistical {
/// 记录数据
/// [data] 待记录的数据
///
void
record
({
@
required
DataReportEntity
data
})
{
void
record
({
required
DataReportEntity
data
})
{
_cachesNumber
++;
print
(
'上报数据=======> cachesNumber:
$_cachesNumber
'
);
Sqlite3Helper
.
create
().
add
(
id:
data
.
id
,
event:
data
.
event
,
type:
data
.
type
,
amount:
data
.
amount
);
Sqlite3Helper
.
create
()
!
.
add
(
id:
data
.
id
,
event:
data
.
event
,
type:
data
.
type
,
amount:
data
.
amount
);
if
(
_cachesNumber
>=
_cachesMax
){
this
.
_startUploadData
();
}
...
...
@@ -54,12 +53,12 @@ class Statistical {
/// 开始上报数据
///
Future
<
void
>
_startUploadData
()
async
{
List
<
Map
<
String
,
dynamic
>>
list
=
await
Sqlite3Helper
.
create
().
query
();
DatareportRepository
.
create
().
dataReport
(
list:
list
).
then
((
val
){
List
<
Map
<
String
,
dynamic
>>
list
=
await
Sqlite3Helper
.
create
()
!
.
query
();
DatareportRepository
.
create
()
!
.
dataReport
(
list:
list
).
then
((
val
){
print
(
'上报数据=======>
$val
'
);
_cachesNumber
=
0
;
}).
whenComplete
(()
async
{
await
Sqlite3Helper
.
create
().
deleteAll
();
await
Sqlite3Helper
.
create
()
!
.
deleteAll
();
});
}
}
\ No newline at end of file
lib/src/xxstatistical.dart
View file @
3c36ecd6
import
'package:flutter/material.dart'
;
import
'package:xxstatistical/src/statistical.dart'
;
import
'entity/datareport_entity.dart'
;
...
...
@@ -15,7 +13,7 @@ class XXStatistical {
/// [cachesMax] 设置缓存的最大数量,默认是50
///
static
Future
<
Null
>
init
({
int
cachesMax
=
50
})
async
{
await
Statistical
.
create
().
init
(
cachesMax:
cachesMax
);
await
Statistical
.
create
()
!
.
init
(
cachesMax:
cachesMax
);
}
///
...
...
@@ -25,7 +23,7 @@ class XXStatistical {
/// [type] 数据类型,1信息流 2宣传口 3搜索结果 4优惠券 5活动配置
/// [amount] 在app中定时周期内累计的上报数量,累计到了10,就是10次
///
static
void
dataReport
({
@
required
DataReportEntity
data
}){
Statistical
.
create
().
record
(
data:
data
);
static
void
dataReport
({
required
DataReportEntity
data
}){
Statistical
.
create
()
!
.
record
(
data:
data
);
}
}
\ No newline at end of file
lib/tracker/exposure_widget.dart
View file @
3c36ecd6
...
...
@@ -9,20 +9,20 @@ class ExposureScrollListener extends StatelessWidget {
final
List
<
Widget
>
slivers
;
final
Axis
scrollDirection
;
final
bool
reverse
;
final
ScrollController
controller
;
final
bool
primary
;
final
ScrollPhysics
physics
;
final
ScrollController
?
controller
;
final
bool
?
primary
;
final
ScrollPhysics
?
physics
;
final
bool
shrinkWrap
;
final
Key
center
;
final
double
cacheExtent
;
final
Key
?
center
;
final
double
?
cacheExtent
;
final
double
anchor
;
final
int
semanticChildCount
;
final
int
?
semanticChildCount
;
final
DragStartBehavior
dragStartBehavior
;
final
String
restorationId
;
final
String
?
restorationId
;
final
Clip
clipBehavior
;
const
ExposureScrollListener
({
Key
key
,
@
required
this
.
slivers
,
Key
?
key
,
required
this
.
slivers
,
this
.
scrollDirection
=
Axis
.
vertical
,
this
.
reverse
=
false
,
this
.
controller
,
...
...
pubspec.yaml
View file @
3c36ecd6
...
...
@@ -6,7 +6,7 @@ homepage:
publish_to
:
none
environment
:
sdk
:
"
>=2.7.0
<3.0.0"
sdk
:
'
>=2.12.0
<3.0.0'
flutter
:
"
>=1.17.0"
dependencies
:
...
...
test/xxapp_statistical_test.dart
deleted
100644 → 0
View file @
8bfeb188
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
test
(
'adds one to input values'
,
()
{
});
}
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