Bug fixes and linting

pull/90/head
Inex Code 2022-06-10 00:13:06 +03:00
parent ad53000415
commit 18d0c2c40f
35 changed files with 208 additions and 152 deletions

View File

@ -82,6 +82,7 @@ ThemeData darkTheme = lightTheme.copyWith(
),
);
const EdgeInsets paddingH15V30 = EdgeInsets.symmetric(horizontal: 15, vertical: 30);
const EdgeInsets paddingH15V30 =
EdgeInsets.symmetric(horizontal: 15, vertical: 30);
const EdgeInsets paddingH15V0 = EdgeInsets.symmetric(horizontal: 15);

View File

@ -25,7 +25,8 @@ class HiveConfig {
await Hive.openBox(BNames.appSettingsBox);
final HiveAesCipher cipher = HiveAesCipher(
await getEncryptedKey(BNames.serverInstallationEncryptionKey),);
await getEncryptedKey(BNames.serverInstallationEncryptionKey),
);
await Hive.openBox<User>(BNames.usersDeprecated);
await Hive.openBox<User>(BNames.usersBox, encryptionCipher: cipher);

View File

@ -63,9 +63,11 @@ final TextStyle buttonTitleText = defaultTextStyle.copyWith(
height: 1,
);
final TextStyle mediumStyle = defaultTextStyle.copyWith(fontSize: 13, height: 1.53);
final TextStyle mediumStyle =
defaultTextStyle.copyWith(fontSize: 13, height: 1.53);
final TextStyle smallStyle = defaultTextStyle.copyWith(fontSize: 11, height: 1.45);
final TextStyle smallStyle =
defaultTextStyle.copyWith(fontSize: 11, height: 1.45);
const TextStyle progressTextStyleLight = TextStyle(
fontSize: 11,

View File

@ -61,7 +61,6 @@ class Loading extends DomainSetupState {
enum LoadingTypes { loadingDomain, saving }
class Loaded extends DomainSetupState {
Loaded(this.domain);
final String domain;
}

View File

@ -12,7 +12,8 @@ class ProvidersCubit extends Cubit<ProvidersState> {
ProvidersCubit() : super(InitialProviderState());
void connect(final ProviderModel provider) {
final ProvidersState newState = state.updateElement(provider, StateType.stable);
final ProvidersState newState =
state.updateElement(provider, StateType.stable);
emit(newState);
}
}

View File

@ -19,8 +19,12 @@ class RecoveryKeyCubit
if (status == null) {
emit(state.copyWith(loadingStatus: LoadingStatus.error));
} else {
emit(state.copyWith(
status: status, loadingStatus: LoadingStatus.success,),);
emit(
state.copyWith(
status: status,
loadingStatus: LoadingStatus.success,
),
);
}
} else {
emit(state.copyWith(loadingStatus: LoadingStatus.uninitialized));
@ -44,7 +48,8 @@ class RecoveryKeyCubit
emit(state.copyWith(loadingStatus: LoadingStatus.error));
} else {
emit(
state.copyWith(status: status, loadingStatus: LoadingStatus.success),);
state.copyWith(status: status, loadingStatus: LoadingStatus.success),
);
}
}
@ -69,7 +74,6 @@ class RecoveryKeyCubit
}
class GenerationError extends Error {
GenerationError(this.message);
final String message;
}

View File

@ -18,12 +18,14 @@ class ServerDetailsCubit extends Cubit<ServerDetailsState> {
if (isReadyToCheck) {
emit(ServerDetailsLoading());
final ServerDetailsRepositoryDto data = await repository.load();
emit(Loaded(
serverInfo: data.hetznerServerInfo,
autoUpgradeSettings: data.autoUpgradeSettings,
serverTimezone: data.serverTimezone,
checkTime: DateTime.now(),
),);
emit(
Loaded(
serverInfo: data.hetznerServerInfo,
autoUpgradeSettings: data.autoUpgradeSettings,
serverTimezone: data.serverTimezone,
checkTime: DateTime.now(),
),
);
} else {
emit(ServerDetailsNotReady());
}

View File

@ -19,7 +19,6 @@ class ServerDetailsRepository {
}
class ServerDetailsRepositoryDto {
ServerDetailsRepositoryDto({
required this.hetznerServerInfo,
required this.serverTimezone,

View File

@ -146,8 +146,9 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
}
}
void startServerIfDnsIsOkay(
{final ServerInstallationNotFinished? state,}) async {
void startServerIfDnsIsOkay({
final ServerInstallationNotFinished? state,
}) async {
final ServerInstallationNotFinished dataState =
state ?? this.state as ServerInstallationNotFinished;
@ -345,7 +346,9 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
}
void tryToRecover(
final String token, final ServerRecoveryMethods method,) async {
final String token,
final ServerRecoveryMethods method,
) async {
final ServerInstallationRecovery dataState =
state as ServerInstallationRecovery;
final ServerDomain? serverDomain = dataState.serverDomain;
@ -395,6 +398,9 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
}
void revertRecoveryStep() {
if (state is ServerInstallationEmpty) {
return;
}
final ServerInstallationRecovery dataState =
state as ServerInstallationRecovery;
switch (dataState.currentStep) {
@ -535,7 +541,8 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
}
void finishRecoveryProcess(
final BackblazeCredential backblazeCredential,) async {
final BackblazeCredential backblazeCredential,
) async {
await repository.saveIsServerStarted(true);
await repository.saveIsServerResetedFirstTime(true);
await repository.saveIsServerResetedSecondTime(true);

View File

@ -4,11 +4,12 @@ part 'backblaze_bucket.g.dart';
@HiveType(typeId: 6)
class BackblazeBucket {
BackblazeBucket(
{required this.bucketId,
required this.bucketName,
required this.applicationKeyId,
required this.applicationKey,});
BackblazeBucket({
required this.bucketId,
required this.bucketName,
required this.applicationKeyId,
required this.applicationKey,
});
@HiveField(0)
final String bucketId;

View File

@ -35,15 +35,16 @@ class ServerHostingDetails {
@HiveField(6, defaultValue: ServerProvider.hetzner)
final ServerProvider provider;
ServerHostingDetails copyWith({final DateTime? startTime}) => ServerHostingDetails(
startTime: startTime ?? this.startTime,
createTime: createTime,
id: id,
ip4: ip4,
volume: volume,
apiToken: apiToken,
provider: provider,
);
ServerHostingDetails copyWith({final DateTime? startTime}) =>
ServerHostingDetails(
startTime: startTime ?? this.startTime,
createTime: createTime,
id: id,
ip4: ip4,
volume: volume,
apiToken: apiToken,
provider: provider,
);
@override
String toString() => id.toString();

View File

@ -4,7 +4,6 @@ part 'api_token.g.dart';
@JsonSerializable()
class ApiToken {
factory ApiToken.fromJson(final Map<String, dynamic> json) =>
_$ApiTokenFromJson(json);
ApiToken({

View File

@ -4,8 +4,8 @@ part 'backup.g.dart';
@JsonSerializable()
class Backup {
factory Backup.fromJson(final Map<String, dynamic> json) => _$BackupFromJson(json);
factory Backup.fromJson(final Map<String, dynamic> json) =>
_$BackupFromJson(json);
Backup({required this.time, required this.id});
// Time of the backup
@ -33,13 +33,13 @@ enum BackupStatusEnum {
@JsonSerializable()
class BackupStatus {
factory BackupStatus.fromJson(final Map<String, dynamic> json) =>
_$BackupStatusFromJson(json);
BackupStatus(
{required this.status,
required this.progress,
required this.errorMessage,});
BackupStatus({
required this.status,
required this.progress,
required this.errorMessage,
});
final BackupStatusEnum status;
final double progress;

View File

@ -4,7 +4,6 @@ part 'device_token.g.dart';
@JsonSerializable()
class DeviceToken {
factory DeviceToken.fromJson(final Map<String, dynamic> json) =>
_$DeviceTokenFromJson(json);
DeviceToken({

View File

@ -1,5 +1,4 @@
class ServerStatus {
ServerStatus({
required this.http,
this.imap = StatusTypes.nodata,
@ -10,10 +9,10 @@ class ServerStatus {
final StatusTypes smtp;
ServerStatus fromJson(final Map<String, dynamic> json) => ServerStatus(
http: statusTypeFromNumber(json['http']),
imap: statusTypeFromNumber(json['imap']),
smtp: statusTypeFromNumber(json['smtp']),
);
http: statusTypeFromNumber(json['http']),
imap: statusTypeFromNumber(json['imap']),
smtp: statusTypeFromNumber(json['smtp']),
);
}
StatusTypes statusTypeFromNumber(final int? number) {

View File

@ -55,7 +55,7 @@ class _BrandMarkdownState extends State<BrandMarkdown> {
color: isDark ? BrandColors.white : null,
),
);
return Markdown(
return MarkdownBody(
shrinkWrap: true,
styleSheet: markdown,
onTapLink: (final String text, final String? href, final String title) {

View File

@ -8,19 +8,19 @@ class BrandError extends StatelessWidget {
@override
Widget build(final BuildContext context) => SafeArea(
child: Scaffold(
body: Center(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(error.toString()),
const Text('stackTrace: '),
Text(stackTrace.toString()),
],
child: Scaffold(
body: Center(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(error.toString()),
const Text('stackTrace: '),
Text(stackTrace.toString()),
],
),
),
),
),
),
);
);
}

View File

@ -66,7 +66,7 @@ class _KeyDisplay extends StatelessWidget {
const SizedBox(height: 16),
Text(
'devices.add_new_device_screen.tip'.tr(),
style: Theme.of(context).textTheme.bodyMedium!,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),

View File

@ -234,7 +234,9 @@ class _RecoveryKeyConfigurationState extends State<RecoveryKeyConfiguration> {
: null,
expirationDate: _isExpirationToggled ? _selectedDate : null,
);
if (!mounted) return;
if (!mounted) {
return;
}
setState(() {
_isLoading = false;
});

View File

@ -8,11 +8,11 @@ import 'package:intl/intl.dart';
class CpuChart extends StatelessWidget {
const CpuChart({
final Key? key,
required this.data,
required this.period,
required this.start,
}) : super(key: key);
final super.key,
});
final List<TimeSeriesData> data;
final Period period;

View File

@ -10,11 +10,11 @@ import 'package:intl/intl.dart';
class NetworkChart extends StatelessWidget {
const NetworkChart({
final Key? key,
required this.listData,
required this.period,
required this.start,
}) : super(key: key);
final super.key,
});
final List<List<TimeSeriesData>> listData;
final Period period;

View File

@ -567,8 +567,13 @@ class _HowTo extends StatelessWidget {
isExpended: true,
child: Padding(
padding: paddingH15V0,
child: BrandMarkdown(
fileName: fileName,
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 16),
children: [
BrandMarkdown(
fileName: fileName,
),
],
),
),
);

View File

@ -17,8 +17,8 @@ class RecoverByNewDeviceKeyInstruction extends StatelessWidget {
heroSubtitle: 'recovering.method_device_description'.tr(),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed: () =>
context.read<ServerInstallationCubit>().revertRecoveryStep(),
onBackButtonPressed:
context.read<ServerInstallationCubit>().revertRecoveryStep,
children: [
FilledButton(
title: 'recovering.method_device_button'.tr(),

View File

@ -28,8 +28,8 @@ class RecoverByOldTokenInstruction extends StatelessWidget {
heroTitle: 'recovering.recovery_main_header'.tr(),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed: () =>
context.read<ServerInstallationCubit>().revertRecoveryStep(),
onBackButtonPressed:
context.read<ServerInstallationCubit>().revertRecoveryStep,
children: [
BrandMarkdown(
fileName: instructionFilename,

View File

@ -31,8 +31,8 @@ class RecoverByRecoveryKey extends StatelessWidget {
heroSubtitle: 'recovering.method_recovery_input_description'.tr(),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed: () =>
context.read<ServerInstallationCubit>().revertRecoveryStep(),
onBackButtonPressed:
context.read<ServerInstallationCubit>().revertRecoveryStep,
children: [
CubitFormTextField(
formFieldCubit:

View File

@ -10,7 +10,7 @@ import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.da
import 'package:selfprivacy/ui/components/brand_md/brand_md.dart';
class RecoveryConfirmBackblaze extends StatelessWidget {
const RecoveryConfirmBackblaze({final Key? key}) : super(key: key);
const RecoveryConfirmBackblaze({final super.key});
@override
Widget build(final BuildContext context) {
@ -59,13 +59,17 @@ class RecoveryConfirmBackblaze extends StatelessWidget {
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (final BuildContext context) =>
const BrandBottomSheet(
builder: (final BuildContext context) => BrandBottomSheet(
isExpended: true,
child: Padding(
padding: paddingH15V0,
child: BrandMarkdown(
fileName: 'how_backblaze',
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 16),
children: const [
BrandMarkdown(
fileName: 'how_backblaze',
),
],
),
),
),

View File

@ -52,13 +52,17 @@ class RecoveryConfirmCloudflare extends StatelessWidget {
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (final BuildContext context) =>
const BrandBottomSheet(
builder: (final BuildContext context) => BrandBottomSheet(
isExpended: true,
child: Padding(
padding: paddingH15V0,
child: BrandMarkdown(
fileName: 'how_cloudflare',
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 16),
children: const [
BrandMarkdown(
fileName: 'how_cloudflare',
),
],
),
),
),

View File

@ -54,13 +54,17 @@ class RecoveryHetznerConnected extends StatelessWidget {
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (final BuildContext context) =>
const BrandBottomSheet(
builder: (final BuildContext context) => BrandBottomSheet(
isExpended: true,
child: Padding(
padding: paddingH15V0,
child: BrandMarkdown(
fileName: 'how_hetzner',
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 16),
children: const [
BrandMarkdown(
fileName: 'how_hetzner',
),
],
),
),
),

View File

@ -17,6 +17,8 @@ class RecoveryMethodSelect extends StatelessWidget {
heroSubtitle: 'recovering.method_select_description'.tr(),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed:
context.read<ServerInstallationCubit>().revertRecoveryStep,
children: [
BrandCards.outlined(
child: ListTile(

View File

@ -108,10 +108,6 @@ class SelectDomainToRecover extends StatelessWidget {
heroSubtitle: 'recovering.domain_recovery_description'.tr(),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed:
serverInstallation is ServerInstallationRecovery
? serverInstallation.clearAppConfig
: null,
children: [
CubitFormTextField(
formFieldCubit:

View File

@ -2,10 +2,9 @@ part of 'users.dart';
class _UserDetails extends StatelessWidget {
const _UserDetails({
final Key? key,
required this.user,
required this.isRootUser,
}) : super(key: key);
});
final User user;
final bool isRootUser;

View File

@ -32,7 +32,9 @@ extension TextExtension on Text {
final String? semanticsLabel,
final TextWidthBasis? textWidthBasis,
final TextStyle? style,
}) => Text(data!,
}) =>
Text(
data!,
key: key ?? this.key,
strutStyle: strutStyle ?? this.strutStyle,
textAlign: textAlign ?? this.textAlign,
@ -44,5 +46,6 @@ extension TextExtension on Text {
maxLines: maxLines ?? this.maxLines,
semanticsLabel: semanticsLabel ?? this.semanticsLabel,
textWidthBasis: textWidthBasis ?? this.textWidthBasis,
style: style != null ? this.style?.merge(style) ?? style : this.style,);
style: style != null ? this.style?.merge(style) ?? style : this.style,
);
}

View File

@ -12,24 +12,25 @@ Function transitionsBuilder = (
final Animation<double> animation,
final Animation<double> secondaryAnimation,
final Widget child,
) => SlideTransition(
position: Tween<Offset>(
begin: const Offset(0, 1),
end: Offset.zero,
).animate(animation),
child: Container(
decoration: animation.isCompleted
? null
: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.black,
) =>
SlideTransition(
position: Tween<Offset>(
begin: const Offset(0, 1),
end: Offset.zero,
).animate(animation),
child: Container(
decoration: animation.isCompleted
? null
: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.black,
),
),
),
),
child: child,
),
);
child: child,
),
);
class SlideBottomRoute extends PageRouteBuilder {
SlideBottomRoute(this.widget)
@ -37,7 +38,11 @@ class SlideBottomRoute extends PageRouteBuilder {
transitionDuration: const Duration(milliseconds: 150),
pageBuilder: pageBuilder(widget),
transitionsBuilder: transitionsBuilder as Widget Function(
BuildContext, Animation<double>, Animation<double>, Widget,),
BuildContext,
Animation<double>,
Animation<double>,
Widget,
),
);
final Widget widget;

View File

@ -12,31 +12,36 @@ Function transitionsBuilder = (
final Animation<double> animation,
final Animation<double> secondaryAnimation,
final Widget child,
) => SlideTransition(
position: Tween<Offset>(
begin: const Offset(-1, 0),
end: Offset.zero,
).animate(animation),
child: Container(
decoration: animation.isCompleted
? null
: const BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black,
) =>
SlideTransition(
position: Tween<Offset>(
begin: const Offset(-1, 0),
end: Offset.zero,
).animate(animation),
child: Container(
decoration: animation.isCompleted
? null
: const BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black,
),
),
),
),
child: child,
),
);
child: child,
),
);
class SlideRightRoute extends PageRouteBuilder {
SlideRightRoute(this.widget)
: super(
pageBuilder: pageBuilder(widget),
transitionsBuilder: transitionsBuilder as Widget Function(
BuildContext, Animation<double>, Animation<double>, Widget,),
BuildContext,
Animation<double>,
Animation<double>,
Widget,
),
);
final Widget widget;

View File

@ -6,9 +6,12 @@ void main() {
group('StringGenerators', () {
group('Basic', () {
test('assert chart empty', () {
expect(() {
StringGenerators.getRandomString(8);
}, throwsAssertionError,);
expect(
() {
StringGenerators.getRandomString(8);
},
throwsAssertionError,
);
});
test('only lowercase string', () {
@ -27,8 +30,11 @@ void main() {
test('only uppercase string', () {
const int length = 8;
final String generatedString = StringGenerators.getRandomString(length,
hasLowercaseLetters: false, hasUppercaseLetters: true,);
final String generatedString = StringGenerators.getRandomString(
length,
hasLowercaseLetters: false,
hasUppercaseLetters: true,
);
expect(generatedString, isNot(matches(regExpNewLines)));
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
@ -41,10 +47,12 @@ void main() {
test('only numbers string', () {
const int length = 8;
final String generatedString = StringGenerators.getRandomString(length,
hasLowercaseLetters: false,
hasUppercaseLetters: false,
hasNumbers: true,);
final String generatedString = StringGenerators.getRandomString(
length,
hasLowercaseLetters: false,
hasUppercaseLetters: false,
hasNumbers: true,
);
expect(generatedString, isNot(matches(regExpNewLines)));
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
@ -78,12 +86,14 @@ void main() {
group('Strict mode', () {
test('All', () {
const int length = 5;
final String generatedString = StringGenerators.getRandomString(length,
hasLowercaseLetters: true,
hasUppercaseLetters: true,
hasNumbers: true,
hasSymbols: true,
isStrict: true,);
final String generatedString = StringGenerators.getRandomString(
length,
hasLowercaseLetters: true,
hasUppercaseLetters: true,
hasNumbers: true,
hasSymbols: true,
isStrict: true,
);
expect(generatedString, isNot(matches(regExpNewLines)));
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
@ -95,12 +105,14 @@ void main() {
});
test('Lowercase letters and numbers', () {
const int length = 3;
final String generatedString = StringGenerators.getRandomString(length,
hasLowercaseLetters: true,
hasUppercaseLetters: false,
hasNumbers: true,
hasSymbols: false,
isStrict: true,);
final String generatedString = StringGenerators.getRandomString(
length,
hasLowercaseLetters: true,
hasUppercaseLetters: false,
hasNumbers: true,
hasSymbols: false,
isStrict: true,
);
expect(generatedString, isNot(matches(regExpNewLines)));
expect(generatedString, isNot(matches(regExpWhiteSpaces)));