lint work

This commit is contained in:
Christien Rioux 2023-07-26 15:58:38 -04:00
parent 6e8725f569
commit fe9d9f8aca
8 changed files with 129 additions and 117 deletions

View File

@ -1,4 +1,5 @@
import 'package:animated_theme_switcher/animated_theme_switcher.dart'; import 'package:animated_theme_switcher/animated_theme_switcher.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -9,7 +10,8 @@ import 'router/router.dart';
class VeilidChatApp extends ConsumerWidget { class VeilidChatApp extends ConsumerWidget {
const VeilidChatApp({ const VeilidChatApp({
required this.theme, super.key, required this.theme,
super.key,
}); });
final ThemeData theme; final ThemeData theme;
@ -23,23 +25,24 @@ class VeilidChatApp extends ConsumerWidget {
return ThemeProvider( return ThemeProvider(
initTheme: theme, initTheme: theme,
builder: (_, theme) => LocalizationProvider( builder: (_, theme) => LocalizationProvider(
state: LocalizationProvider.of(context).state, state: LocalizationProvider.of(context).state,
child: MaterialApp.router( child: MaterialApp.router(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
routerConfig: router, routerConfig: router,
title: translate('app.title'), title: translate('app.title'),
theme: theme, theme: theme,
localizationsDelegates: [ localizationsDelegates: [
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
FormBuilderLocalizations.delegate, FormBuilderLocalizations.delegate,
localizationDelegate localizationDelegate
], ],
supportedLocales: localizationDelegate.supportedLocales, supportedLocales: localizationDelegate.supportedLocales,
locale: localizationDelegate.currentLocale, locale: localizationDelegate.currentLocale,
)), )),
); );
} }
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);

View File

@ -67,7 +67,7 @@ class CallbackPrinter extends LoggyPrinter {
callback?.call(record); callback?.call(record);
} }
void setCallback(Function(LogRecord)? cb) { void setCallback(void Function(LogRecord)? cb) {
callback = cb; callback = cb;
} }
} }
@ -80,9 +80,9 @@ extension TraceLoggy on Loggy {
} }
LogOptions getLogOptions(LogLevel? level) => LogOptions( LogOptions getLogOptions(LogLevel? level) => LogOptions(
level ?? LogLevel.all, level ?? LogLevel.all,
stackTraceLevel: LogLevel.error, stackTraceLevel: LogLevel.error,
); );
class RootLoggy implements LoggyType { class RootLoggy implements LoggyType {
@override @override

View File

@ -5,12 +5,13 @@ class StateLogger extends ProviderObserver {
const StateLogger(); const StateLogger();
@override @override
void didUpdateProvider( void didUpdateProvider(
ProviderBase provider, ProviderBase<Object?> provider,
Object? previousValue, Object? previousValue,
Object? newValue, Object? newValue,
ProviderContainer container, ProviderContainer container,
) { ) {
log.debug('''{ log.debug('''
{
provider: ${provider.name ?? provider.runtimeType}, provider: ${provider.name ?? provider.runtimeType},
oldValue: $previousValue, oldValue: $previousValue,
newValue: $newValue newValue: $newValue

View File

@ -1,4 +1,5 @@
import 'package:awesome_extensions/awesome_extensions.dart'; import 'package:awesome_extensions/awesome_extensions.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -33,11 +34,11 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
final localAccounts = ref.read(localAccountsProvider.notifier); final localAccounts = ref.read(localAccountsProvider.notifier);
final logins = ref.read(loginsProvider.notifier); final logins = ref.read(loginsProvider.notifier);
final profile = proto.Profile(); final profile = proto.Profile()
profile.name = _formKey.currentState!.fields[formFieldName]!.value; ..name = _formKey.currentState!.fields[formFieldName]!.value as String
profile.title = _formKey.currentState!.fields[formFieldTitle]!.value; ..title =
final account = proto.Account(); _formKey.currentState!.fields[formFieldTitle]!.value as String;
account.profile = profile; final account = proto.Account()..profile = profile;
final localAccount = await localAccounts.newAccount( final localAccount = await localAccounts.newAccount(
identityMaster: imws.identityMaster, identityMaster: imws.identityMaster,
identitySecret: imws.identitySecret, identitySecret: imws.identitySecret,
@ -46,65 +47,67 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
// Log in the new account by default with no pin // Log in the new account by default with no pin
final ok = await logins final ok = await logins
.loginWithNone(localAccount.identityMaster.masterRecordKey); .loginWithNone(localAccount.identityMaster.masterRecordKey);
assert(ok == true); assert(ok == true, 'login with none should never fail');
} catch (e) { } on Exception catch (_) {
await imws.delete(); await imws.delete();
rethrow; rethrow;
} }
} }
Widget _newAccountForm(BuildContext context, Widget _newAccountForm(BuildContext context,
{required Future<void> Function(GlobalKey<FormBuilderState>) onSubmit}) => FormBuilder( {required Future<void> Function(GlobalKey<FormBuilderState>)
key: _formKey, onSubmit}) =>
child: ListView( FormBuilder(
children: [ key: _formKey,
Text(translate('new_account_page.header')) child: ListView(
.textStyle(context.headlineSmall) children: [
.paddingSymmetric(vertical: 16), Text(translate('new_account_page.header'))
FormBuilderTextField( .textStyle(context.headlineSmall)
autofocus: true, .paddingSymmetric(vertical: 16),
name: formFieldName, FormBuilderTextField(
decoration: autofocus: true,
InputDecoration(hintText: translate('account.form_name')), name: formFieldName,
maxLength: 64, decoration:
// The validator receives the text that the user has entered. InputDecoration(hintText: translate('account.form_name')),
validator: FormBuilderValidators.compose([ maxLength: 64,
FormBuilderValidators.required(), // The validator receives the text that the user has entered.
]), validator: FormBuilderValidators.compose([
), FormBuilderValidators.required(),
FormBuilderTextField( ]),
name: formFieldTitle, ),
maxLength: 64, FormBuilderTextField(
decoration: name: formFieldTitle,
InputDecoration(hintText: translate('account.form_title')), maxLength: 64,
), decoration:
Row(children: [ InputDecoration(hintText: translate('account.form_title')),
const Spacer(), ),
Text(translate('new_account_page.instructions')) Row(children: [
.toCenter() const Spacer(),
.flexible(flex: 6), Text(translate('new_account_page.instructions'))
const Spacer(), .toCenter()
]).paddingSymmetric(vertical: 4), .flexible(flex: 6),
ElevatedButton( const Spacer(),
onPressed: () async { ]).paddingSymmetric(vertical: 4),
if (_formKey.currentState?.saveAndValidate() ?? false) { ElevatedButton(
setState(() { onPressed: () async {
isInAsyncCall = true; if (_formKey.currentState?.saveAndValidate() ?? false) {
});
try {
await onSubmit(_formKey);
} finally {
setState(() { setState(() {
isInAsyncCall = false; isInAsyncCall = true;
}); });
try {
await onSubmit(_formKey);
} finally {
setState(() {
isInAsyncCall = false;
});
}
} }
} },
}, child: Text(translate('new_account_page.create')),
child: Text(translate('new_account_page.create')), ).paddingSymmetric(vertical: 4).alignAtCenterRight(),
).paddingSymmetric(vertical: 4).alignAtCenterRight(), ],
], ),
), );
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -125,7 +128,7 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
try { try {
await createAccount(); await createAccount();
} catch (e) { } on Exception catch (e) {
await QuickAlert.show( await QuickAlert.show(
context: context, context: context,
type: QuickAlertType.error, type: QuickAlertType.error,
@ -140,6 +143,7 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
).paddingSymmetric(horizontal: 24, vertical: 8), ).paddingSymmetric(horizontal: 24, vertical: 8),
).withModalHUD(context, displayModalHUD); ).withModalHUD(context, displayModalHUD);
} }
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);

View File

@ -26,12 +26,12 @@ class ThemeService {
final isPlatformDark = final isPlatformDark =
WidgetsBinding.instance.platformDispatcher.platformBrightness == WidgetsBinding.instance.platformDispatcher.platformBrightness ==
Brightness.dark; Brightness.dark;
themeName = isPlatformDark ? 'light' : 'dark'; themeName = isPlatformDark ? 'dark' : 'light';
} }
return themeName; return themeName;
} }
ThemeData? get initial { ThemeData get initial {
var themeName = prefs.getString('theme'); var themeName = prefs.getString('theme');
if (themeName == null) { if (themeName == null) {
final isPlatformDark = final isPlatformDark =
@ -39,15 +39,15 @@ class ThemeService {
Brightness.dark; Brightness.dark;
themeName = isPlatformDark ? 'dark' : 'light'; themeName = isPlatformDark ? 'dark' : 'light';
} }
return allThemes[themeName]; return allThemes[themeName] ?? allThemes['light']!;
} }
save(String newThemeName) { Future<void> save(String newThemeName) async {
final currentThemeName = prefs.getString('theme'); final currentThemeName = prefs.getString('theme');
if (currentThemeName != null) { if (currentThemeName != null) {
prefs.setString('previousThemeName', currentThemeName); await prefs.setString('previousThemeName', currentThemeName);
} }
prefs.setString('theme', newThemeName); await prefs.setString('theme', newThemeName);
} }
ThemeData getByName(String name) => allThemes[name]!; ThemeData getByName(String name) => allThemes[name]!;

View File

@ -1,14 +1,15 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
T jsonDecodeBytes<T>( T jsonDecodeBytes<T>(T Function(dynamic) fromJson, Uint8List data) =>
T Function(Map<String, dynamic>) fromJson, Uint8List data) => fromJson(jsonDecode(utf8.decode(data))); fromJson(jsonDecode(utf8.decode(data)));
Uint8List jsonEncodeBytes(Object? object, Uint8List jsonEncodeBytes(Object? object,
{Object? Function(Object?)? toEncodable}) => Uint8List.fromList( {Object? Function(Object?)? toEncodable}) =>
utf8.encode(jsonEncode(object, toEncodable: toEncodable))); Uint8List.fromList(
utf8.encode(jsonEncode(object, toEncodable: toEncodable)));
Future<Uint8List> jsonUpdateBytes<T>(T Function(Map<String, dynamic>) fromJson, Future<Uint8List> jsonUpdateBytes<T>(T Function(dynamic) fromJson,
Uint8List oldBytes, Future<T> Function(T) update) async { Uint8List oldBytes, Future<T> Function(T) update) async {
final oldObj = fromJson(jsonDecode(utf8.decode(oldBytes))); final oldObj = fromJson(jsonDecode(utf8.decode(oldBytes)));
final newObj = await update(oldObj); final newObj = await update(oldObj);
@ -16,7 +17,9 @@ Future<Uint8List> jsonUpdateBytes<T>(T Function(Map<String, dynamic>) fromJson,
} }
Future<Uint8List> Function(Uint8List) jsonUpdate<T>( Future<Uint8List> Function(Uint8List) jsonUpdate<T>(
T Function(Map<String, dynamic>) fromJson, Future<T> Function(T) update) => (oldBytes) => jsonUpdateBytes(fromJson, oldBytes, update); T Function(dynamic) fromJson, Future<T> Function(T) update) =>
(oldBytes) => jsonUpdateBytes(fromJson, oldBytes, update);
T Function(Object?) genericFromJson<T>( T Function(Object?) genericFromJson<T>(
T Function(Map<String, dynamic>) fromJsonMap) => (json) => fromJsonMap(json as Map<String, dynamic>); T Function(Map<String, dynamic>) fromJsonMap) =>
(json) => fromJsonMap(json! as Map<String, dynamic>);

View File

@ -3,19 +3,20 @@ import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart';
extension BorderExt on Widget { extension BorderExt on Widget {
Container debugBorder() => DecoratedBox( DecoratedBox debugBorder() => DecoratedBox(
decoration: BoxDecoration(border: Border.all(color: Colors.redAccent)), decoration: BoxDecoration(border: Border.all(color: Colors.redAccent)),
child: this); child: this);
} }
extension ModalProgressExt on Widget { extension ModalProgressExt on Widget {
BlurryModalProgressHUD withModalHUD(BuildContext context, bool isLoading) => BlurryModalProgressHUD( BlurryModalProgressHUD withModalHUD(BuildContext context, bool isLoading) =>
inAsyncCall: isLoading, BlurryModalProgressHUD(
blurEffectIntensity: 4, inAsyncCall: isLoading,
progressIndicator: SpinKitFoldingCube( blurEffectIntensity: 4,
color: Theme.of(context).highlightColor, progressIndicator: SpinKitFoldingCube(
size: 90, color: Theme.of(context).highlightColor,
), size: 90,
color: Theme.of(context).shadowColor, ),
child: this); color: Theme.of(context).shadowColor,
child: this);
} }

View File

@ -7,7 +7,6 @@ import '../tools/tools.dart';
import 'veilid_support.dart'; import 'veilid_support.dart';
class DHTRecord { class DHTRecord {
DHTRecord( DHTRecord(
{required VeilidRoutingContext dhtctx, {required VeilidRoutingContext dhtctx,
required DHTRecordDescriptor recordDescriptor, required DHTRecordDescriptor recordDescriptor,
@ -46,8 +45,7 @@ class DHTRecord {
static Future<DHTRecord> openRead( static Future<DHTRecord> openRead(
VeilidRoutingContext dhtctx, TypedKey recordKey, VeilidRoutingContext dhtctx, TypedKey recordKey,
{int defaultSubkey = 0, DHTRecordCrypto? crypto}) async { {int defaultSubkey = 0, DHTRecordCrypto? crypto}) async {
final recordDescriptor = final recordDescriptor = await dhtctx.openDHTRecord(recordKey, null);
await dhtctx.openDHTRecord(recordKey, null);
final rec = DHTRecord( final rec = DHTRecord(
dhtctx: dhtctx, dhtctx: dhtctx,
recordDescriptor: recordDescriptor, recordDescriptor: recordDescriptor,
@ -64,8 +62,7 @@ class DHTRecord {
int defaultSubkey = 0, int defaultSubkey = 0,
DHTRecordCrypto? crypto, DHTRecordCrypto? crypto,
}) async { }) async {
final recordDescriptor = final recordDescriptor = await dhtctx.openDHTRecord(recordKey, writer);
await dhtctx.openDHTRecord(recordKey, writer);
final rec = DHTRecord( final rec = DHTRecord(
dhtctx: dhtctx, dhtctx: dhtctx,
recordDescriptor: recordDescriptor, recordDescriptor: recordDescriptor,
@ -112,7 +109,7 @@ class DHTRecord {
final out = await scopeFunction(this); final out = await scopeFunction(this);
await close(); await close();
return out; return out;
} catch (_) { } on Exception catch (_) {
await delete(); await delete();
rethrow; rethrow;
} }
@ -128,7 +125,7 @@ class DHTRecord {
return _crypto.decrypt(valueData.data, subkey); return _crypto.decrypt(valueData.data, subkey);
} }
Future<T?> getJson<T>(T Function(Map<String, dynamic>) fromJson, Future<T?> getJson<T>(T Function(dynamic) fromJson,
{int subkey = -1, bool forceRefresh = false}) async { {int subkey = -1, bool forceRefresh = false}) async {
final data = await get(subkey: subkey, forceRefresh: forceRefresh); final data = await get(subkey: subkey, forceRefresh: forceRefresh);
if (data == null) { if (data == null) {
@ -177,17 +174,20 @@ class DHTRecord {
} while (valueData != null); } while (valueData != null);
} }
Future<void> eventualWriteJson<T>(T newValue, {int subkey = -1}) => eventualWriteBytes(jsonEncodeBytes(newValue), subkey: subkey); Future<void> eventualWriteJson<T>(T newValue, {int subkey = -1}) =>
eventualWriteBytes(jsonEncodeBytes(newValue), subkey: subkey);
Future<void> eventualWriteProtobuf<T extends GeneratedMessage>(T newValue, Future<void> eventualWriteProtobuf<T extends GeneratedMessage>(T newValue,
{int subkey = -1}) => eventualWriteBytes(newValue.writeToBuffer(), subkey: subkey); {int subkey = -1}) =>
eventualWriteBytes(newValue.writeToBuffer(), subkey: subkey);
Future<void> eventualUpdateJson<T>( Future<void> eventualUpdateJson<T>(
T Function(Map<String, dynamic>) fromJson, Future<T> Function(T) update, T Function(dynamic) fromJson, Future<T> Function(T) update,
{int subkey = -1}) => eventualUpdateBytes(jsonUpdate(fromJson, update), subkey: subkey); {int subkey = -1}) =>
eventualUpdateBytes(jsonUpdate(fromJson, update), subkey: subkey);
Future<void> eventualUpdateProtobuf<T extends GeneratedMessage>( Future<void> eventualUpdateProtobuf<T extends GeneratedMessage>(
T Function(List<int>) fromBuffer, Future<T> Function(T) update, T Function(List<int>) fromBuffer, Future<T> Function(T) update,
{int subkey = -1}) => eventualUpdateBytes(protobufUpdate(fromBuffer, update), {int subkey = -1}) =>
subkey: subkey); eventualUpdateBytes(protobufUpdate(fromBuffer, update), subkey: subkey);
} }