Commit 8bfeb188 authored by 汪林玲's avatar 汪林玲

增加null-safety

parents
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# 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
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
.vscode/
# 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: 1aafb3a8b9b0c36241c5f5b34ee914770f015818
channel: stable
project_type: package
# 小熊有好货统计
```sql
CREATE TABLE IF NOT EXISTS Statistical (
id TEXT NOT NULL,
event INT,
type INT,
amount INT
)
```
### 引入说明
xxstatistical:
git:
url: 'git@git.xiaomanxiong.com:flutter-plugin/xxapp-statistical.git'
ref: 'null-safety'
\ No newline at end of file
import 'package:flutter/foundation.dart';
import 'impl/datareport_repository_impl.dart';
abstract class DatareportRepository {
///
/// 获取单例
///
static DatareportRepository create() {
return DatareportRepositoryImpl.get();
}
///
/// 数据上报接口
/// [list] 待上报的数据
///
Future<dynamic> dataReport({@required List<dynamic> list});
}
\ No newline at end of file
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 get() {
if (_instance == null) {
_instance = DatareportRepositoryImpl._();
}
return _instance;
}
@override
Future dataReport({@required List<dynamic> list}) async{
Options options = Options(headers: {'base_url': 'v6'});
dynamic result = await DSDioUtil.getInstance().post(
'/drp.send',
data:{'data':list},
options:options
);
return result;
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
///
/// 数据上报实体类
/// id、数据的自增id,如优惠券在数据库对应的id
/// event、事件类型,1曝光事件 2点击事件 3流量次数事件
/// type、数据类型,1信息流 2宣传口 3搜索结果 4优惠券 5活动配置
/// amount 在app中定时周期内累计的上报数量,
///
class DataReportEntity {
String id;
int event;
int type;
int amount;
///
/// [id] 数据id,来源服务器
/// [event] 事件类型:1曝光事件 2点击事件 3流量次数事件
/// [type] 数据类型:1信息流 2宣传口 3搜索结果 4优惠券 5活动配置
/// [amount] 点击或曝光的次数
///
DataReportEntity({@required this.id,this.event = 2,this.type = 1,this.amount = 1});
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
class Sqlite3Helper {
Sqlite3Helper._();
static Sqlite3Helper _instance;
static Sqlite3Helper create() {
if (_instance == null) {
_instance = Sqlite3Helper._();
}
return _instance;
}
static Future<Database> database;
///
/// 初始化数据库
///
Future<int> init() async{
database = openDatabase(
join(await getDatabasesPath(), 'xx_database.db'),
onCreate: (db, version) {
return db.execute('CREATE TABLE IF NOT EXISTS Statistical(id TEXT NOT NULL, event INT,type INT,amount INT)');
},
version: 1
);
if(database == null){
print('==========>数据为空');
return Future.value(0);
}else{
return await queryCount();
}
}
///
/// 添加数据
///
void add({@required String id,int event,int type,int amount=1}) async{
if(database != null){
final db = await database;
String sql = 'INSERT INTO Statistical(id,event,type,amount) VALUES(?,?,?,?)';
await db.execute(sql,[id,event,type,amount]);
}
}
///
/// 查询所有数据并根据id,event,type进行计数
///
Future<List<Map<String, dynamic>>> query() async{
if(database != null){
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;
}
return Future.value([]);
}
///
/// 查询数据库记录了多少条数据
///
Future<int> queryCount() async {
if(database != null){
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){
Map<String, dynamic> data =maps[0];
if(data['amount'] is int){
return data['amount'];
}
}
}
return 0;
}
///
/// 删除所有数据
///
Future<int> deleteAll() async{
if(database != null){
final db = await database;
int number = await db.delete('Statistical');
return number;
}
return Future.value(0);
}
}
\ No newline at end of file
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';
class Statistical {
Statistical._();
static Statistical _instance;
static Statistical create() {
if (_instance == null) {
_instance = Statistical._();
}
return _instance;
}
///
/// 设置缓存的最大数量(当达到最大数量之后就上传)
///
int _cachesMax = 0;
///
/// 计数,当前已经缓存的数据
///
int _cachesNumber = 0;
///
/// 初始化
///
Future<Null> init({int cachesMax = 50}) async{
this._cachesMax = cachesMax;
int amount = await Sqlite3Helper.create().init();
_cachesNumber = amount;
if(_cachesNumber>=10){
this._startUploadData();
}
}
///
/// 记录数据
/// [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);
if(_cachesNumber >= _cachesMax){
this._startUploadData();
}
}
///
/// 开始上报数据
///
Future<void> _startUploadData() async{
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();
});
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:xxstatistical/src/statistical.dart';
import 'entity/datareport_entity.dart';
///
/// 默认启动成功之后上报一次
/// 数据量达到50条之后再次上报
///
class XXStatistical {
///
/// 初始化小熊数据上报
/// APP启动上报/缓存日志数量/间隔时间 (暂时支持达到最大缓存日志数上传)
/// [cachesMax] 设置缓存的最大数量,默认是50
///
static Future<Null> init({int cachesMax = 50}) async{
await Statistical.create().init(cachesMax:cachesMax);
}
///
/// 数据上报
/// [id] 数据的自增id,如优惠券在数据库对应的id
/// [event] 事件类型,1曝光事件 2点击事件
/// [type] 数据类型,1信息流 2宣传口 3搜索结果 4优惠券 5活动配置
/// [amount] 在app中定时周期内累计的上报数量,累计到了10,就是10次
///
static void dataReport({@required DataReportEntity data}){
Statistical.create().record(data:data);
}
}
\ No newline at end of file
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';
///
/// 曝光监听组件
///
class ExposureScrollListener extends StatelessWidget {
final List<Widget> slivers;
final Axis scrollDirection;
final bool reverse;
final ScrollController controller;
final bool primary;
final ScrollPhysics physics;
final bool shrinkWrap;
final Key center;
final double cacheExtent;
final double anchor;
final int semanticChildCount;
final DragStartBehavior dragStartBehavior;
final String restorationId;
final Clip clipBehavior;
const ExposureScrollListener({
Key key ,
@required this.slivers,
this.scrollDirection = Axis.vertical,
this.reverse = false,
this.controller,
this.primary,
this.physics,
this.shrinkWrap = false,
this.center,
this.cacheExtent,
this.anchor = 0.0,
this.semanticChildCount,
this.dragStartBehavior = DragStartBehavior.start,
this.restorationId,
this.clipBehavior = Clip.hardEdge
}) : super(key: key);
@override
Widget build(BuildContext context) {
return CustomScrollView(
slivers:slivers,
scrollDirection: scrollDirection,
reverse: reverse,
controller:controller,
primary:primary,
physics:physics,
shrinkWrap:shrinkWrap,
center:center,
cacheExtent:cacheExtent,
anchor:anchor,
semanticChildCount:semanticChildCount,
dragStartBehavior:dragStartBehavior,
restorationId:restorationId,
clipBehavior:clipBehavior
);
}
}
\ No newline at end of file
library xxstatistical;
export 'src/xxstatistical.dart';
export 'src/entity/datareport_entity.dart';
export 'tracker/exposure_widget.dart';
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.1"
base_repository:
dependency: "direct main"
description:
path: "."
ref: null-safety
resolved-ref: "5b60d47410e4bb47d0e8f4fc8c6be00e28b2002d"
url: "git@git.xiaomanxiong.com:flutter-plugin/app-base-repository.git"
source: git
version: "1.0.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.15.0"
dio:
dependency: transitive
description:
name: dio
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.1"
sqflite:
dependency: "direct main"
description:
name: sqflite
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0+4"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1+1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
synchronized:
dependency: transitive
description:
name: synchronized
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
name: xxstatistical
description: 小熊app数据上报插件库.
version: 1.0.0
homepage:
publish_to: none
environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
sqflite: ^2.0.0+4
base_repository:
git:
url: 'git@git.xiaomanxiong.com:flutter-plugin/app-base-repository.git'
ref: 'null-safety'
dev_dependencies:
flutter_test:
sdk: flutter
\ No newline at end of file
import 'package:flutter_test/flutter_test.dart';
void main() {
test('adds one to input values', () {
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment