claude refactorings, flutter best practices, platform dependent changes, general cleanup
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'update_user_index_params.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class UpdateUserIndexParams {
|
||||
String user;
|
||||
String username;
|
||||
String device;
|
||||
int appVersion;
|
||||
String deviceInfo;
|
||||
|
||||
|
||||
UpdateUserIndexParams({
|
||||
required this.user,
|
||||
required this.username,
|
||||
required this.device,
|
||||
required this.appVersion,
|
||||
required this.deviceInfo
|
||||
});
|
||||
|
||||
factory UpdateUserIndexParams.fromJson(Map<String, dynamic> json) => _$UpdateUserIndexParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$UpdateUserIndexParamsToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'update_user_index_params.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
UpdateUserIndexParams _$UpdateUserIndexParamsFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => UpdateUserIndexParams(
|
||||
user: json['user'] as String,
|
||||
username: json['username'] as String,
|
||||
device: json['device'] as String,
|
||||
appVersion: (json['appVersion'] as num).toInt(),
|
||||
deviceInfo: json['deviceInfo'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UpdateUserIndexParamsToJson(
|
||||
UpdateUserIndexParams instance,
|
||||
) => <String, dynamic>{
|
||||
'user': instance.user,
|
||||
'username': instance.username,
|
||||
'device': instance.device,
|
||||
'appVersion': instance.appVersion,
|
||||
'deviceInfo': instance.deviceInfo,
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../../../../../model/account_data.dart';
|
||||
import '../../../mhsl_api.dart';
|
||||
import 'update_user_index_params.dart';
|
||||
|
||||
class UpdateUserIndex extends MhslApi<void> {
|
||||
UpdateUserIndexParams params;
|
||||
UpdateUserIndex(this.params) : super('server/userIndex/update');
|
||||
|
||||
@override
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri) {
|
||||
var data = jsonEncode(params.toJson());
|
||||
log('Updating userindex: ${data.length}');
|
||||
return http.post(uri, body: data);
|
||||
}
|
||||
|
||||
static Future<void> index() async {
|
||||
unawaited(UpdateUserIndex(
|
||||
UpdateUserIndexParams(
|
||||
username: AccountData().getUsername(),
|
||||
user: AccountData().getUserSecret(),
|
||||
device: await AccountData().getDeviceId(),
|
||||
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber),
|
||||
deviceInfo: jsonEncode((await DeviceInfoPlugin().deviceInfo).data).toString(),
|
||||
),
|
||||
).run());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user