Commit 3c36ecd6 authored by 汪林玲's avatar 汪林玲

null-safety

parent 8bfeb188
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
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',
......
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
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;
}
......
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
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
......@@ -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,
......
......@@ -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:
......
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