mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-01-11 07:39:32 -05:00
lint work
This commit is contained in:
parent
6e8725f569
commit
fe9d9f8aca
35
lib/app.dart
35
lib/app.dart
@ -1,4 +1,5 @@
|
||||
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@ -9,7 +10,8 @@ import 'router/router.dart';
|
||||
|
||||
class VeilidChatApp extends ConsumerWidget {
|
||||
const VeilidChatApp({
|
||||
required this.theme, super.key,
|
||||
required this.theme,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final ThemeData theme;
|
||||
@ -23,23 +25,24 @@ class VeilidChatApp extends ConsumerWidget {
|
||||
return ThemeProvider(
|
||||
initTheme: theme,
|
||||
builder: (_, theme) => LocalizationProvider(
|
||||
state: LocalizationProvider.of(context).state,
|
||||
child: MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
routerConfig: router,
|
||||
title: translate('app.title'),
|
||||
theme: theme,
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
FormBuilderLocalizations.delegate,
|
||||
localizationDelegate
|
||||
],
|
||||
supportedLocales: localizationDelegate.supportedLocales,
|
||||
locale: localizationDelegate.currentLocale,
|
||||
)),
|
||||
state: LocalizationProvider.of(context).state,
|
||||
child: MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
routerConfig: router,
|
||||
title: translate('app.title'),
|
||||
theme: theme,
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
FormBuilderLocalizations.delegate,
|
||||
localizationDelegate
|
||||
],
|
||||
supportedLocales: localizationDelegate.supportedLocales,
|
||||
locale: localizationDelegate.currentLocale,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
|
@ -67,7 +67,7 @@ class CallbackPrinter extends LoggyPrinter {
|
||||
callback?.call(record);
|
||||
}
|
||||
|
||||
void setCallback(Function(LogRecord)? cb) {
|
||||
void setCallback(void Function(LogRecord)? cb) {
|
||||
callback = cb;
|
||||
}
|
||||
}
|
||||
@ -80,9 +80,9 @@ extension TraceLoggy on Loggy {
|
||||
}
|
||||
|
||||
LogOptions getLogOptions(LogLevel? level) => LogOptions(
|
||||
level ?? LogLevel.all,
|
||||
stackTraceLevel: LogLevel.error,
|
||||
);
|
||||
level ?? LogLevel.all,
|
||||
stackTraceLevel: LogLevel.error,
|
||||
);
|
||||
|
||||
class RootLoggy implements LoggyType {
|
||||
@override
|
||||
|
@ -5,12 +5,13 @@ class StateLogger extends ProviderObserver {
|
||||
const StateLogger();
|
||||
@override
|
||||
void didUpdateProvider(
|
||||
ProviderBase provider,
|
||||
ProviderBase<Object?> provider,
|
||||
Object? previousValue,
|
||||
Object? newValue,
|
||||
ProviderContainer container,
|
||||
) {
|
||||
log.debug('''{
|
||||
log.debug('''
|
||||
{
|
||||
provider: ${provider.name ?? provider.runtimeType},
|
||||
oldValue: $previousValue,
|
||||
newValue: $newValue
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@ -33,11 +34,11 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
|
||||
final localAccounts = ref.read(localAccountsProvider.notifier);
|
||||
final logins = ref.read(loginsProvider.notifier);
|
||||
|
||||
final profile = proto.Profile();
|
||||
profile.name = _formKey.currentState!.fields[formFieldName]!.value;
|
||||
profile.title = _formKey.currentState!.fields[formFieldTitle]!.value;
|
||||
final account = proto.Account();
|
||||
account.profile = profile;
|
||||
final profile = proto.Profile()
|
||||
..name = _formKey.currentState!.fields[formFieldName]!.value as String
|
||||
..title =
|
||||
_formKey.currentState!.fields[formFieldTitle]!.value as String;
|
||||
final account = proto.Account()..profile = profile;
|
||||
final localAccount = await localAccounts.newAccount(
|
||||
identityMaster: imws.identityMaster,
|
||||
identitySecret: imws.identitySecret,
|
||||
@ -46,65 +47,67 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
|
||||
// Log in the new account by default with no pin
|
||||
final ok = await logins
|
||||
.loginWithNone(localAccount.identityMaster.masterRecordKey);
|
||||
assert(ok == true);
|
||||
} catch (e) {
|
||||
assert(ok == true, 'login with none should never fail');
|
||||
} on Exception catch (_) {
|
||||
await imws.delete();
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _newAccountForm(BuildContext context,
|
||||
{required Future<void> Function(GlobalKey<FormBuilderState>) onSubmit}) => FormBuilder(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
children: [
|
||||
Text(translate('new_account_page.header'))
|
||||
.textStyle(context.headlineSmall)
|
||||
.paddingSymmetric(vertical: 16),
|
||||
FormBuilderTextField(
|
||||
autofocus: true,
|
||||
name: formFieldName,
|
||||
decoration:
|
||||
InputDecoration(hintText: translate('account.form_name')),
|
||||
maxLength: 64,
|
||||
// The validator receives the text that the user has entered.
|
||||
validator: FormBuilderValidators.compose([
|
||||
FormBuilderValidators.required(),
|
||||
]),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: formFieldTitle,
|
||||
maxLength: 64,
|
||||
decoration:
|
||||
InputDecoration(hintText: translate('account.form_title')),
|
||||
),
|
||||
Row(children: [
|
||||
const Spacer(),
|
||||
Text(translate('new_account_page.instructions'))
|
||||
.toCenter()
|
||||
.flexible(flex: 6),
|
||||
const Spacer(),
|
||||
]).paddingSymmetric(vertical: 4),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState?.saveAndValidate() ?? false) {
|
||||
setState(() {
|
||||
isInAsyncCall = true;
|
||||
});
|
||||
try {
|
||||
await onSubmit(_formKey);
|
||||
} finally {
|
||||
{required Future<void> Function(GlobalKey<FormBuilderState>)
|
||||
onSubmit}) =>
|
||||
FormBuilder(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
children: [
|
||||
Text(translate('new_account_page.header'))
|
||||
.textStyle(context.headlineSmall)
|
||||
.paddingSymmetric(vertical: 16),
|
||||
FormBuilderTextField(
|
||||
autofocus: true,
|
||||
name: formFieldName,
|
||||
decoration:
|
||||
InputDecoration(hintText: translate('account.form_name')),
|
||||
maxLength: 64,
|
||||
// The validator receives the text that the user has entered.
|
||||
validator: FormBuilderValidators.compose([
|
||||
FormBuilderValidators.required(),
|
||||
]),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: formFieldTitle,
|
||||
maxLength: 64,
|
||||
decoration:
|
||||
InputDecoration(hintText: translate('account.form_title')),
|
||||
),
|
||||
Row(children: [
|
||||
const Spacer(),
|
||||
Text(translate('new_account_page.instructions'))
|
||||
.toCenter()
|
||||
.flexible(flex: 6),
|
||||
const Spacer(),
|
||||
]).paddingSymmetric(vertical: 4),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState?.saveAndValidate() ?? false) {
|
||||
setState(() {
|
||||
isInAsyncCall = false;
|
||||
isInAsyncCall = true;
|
||||
});
|
||||
try {
|
||||
await onSubmit(_formKey);
|
||||
} finally {
|
||||
setState(() {
|
||||
isInAsyncCall = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Text(translate('new_account_page.create')),
|
||||
).paddingSymmetric(vertical: 4).alignAtCenterRight(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(translate('new_account_page.create')),
|
||||
).paddingSymmetric(vertical: 4).alignAtCenterRight(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -125,7 +128,7 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
|
||||
FocusScope.of(context).unfocus();
|
||||
try {
|
||||
await createAccount();
|
||||
} catch (e) {
|
||||
} on Exception catch (e) {
|
||||
await QuickAlert.show(
|
||||
context: context,
|
||||
type: QuickAlertType.error,
|
||||
@ -140,6 +143,7 @@ class NewAccountPageState extends ConsumerState<NewAccountPage> {
|
||||
).paddingSymmetric(horizontal: 24, vertical: 8),
|
||||
).withModalHUD(context, displayModalHUD);
|
||||
}
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
|
@ -26,12 +26,12 @@ class ThemeService {
|
||||
final isPlatformDark =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness ==
|
||||
Brightness.dark;
|
||||
themeName = isPlatformDark ? 'light' : 'dark';
|
||||
themeName = isPlatformDark ? 'dark' : 'light';
|
||||
}
|
||||
return themeName;
|
||||
}
|
||||
|
||||
ThemeData? get initial {
|
||||
ThemeData get initial {
|
||||
var themeName = prefs.getString('theme');
|
||||
if (themeName == null) {
|
||||
final isPlatformDark =
|
||||
@ -39,15 +39,15 @@ class ThemeService {
|
||||
Brightness.dark;
|
||||
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');
|
||||
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]!;
|
||||
|
@ -1,14 +1,15 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
T jsonDecodeBytes<T>(
|
||||
T Function(Map<String, dynamic>) fromJson, Uint8List data) => fromJson(jsonDecode(utf8.decode(data)));
|
||||
T jsonDecodeBytes<T>(T Function(dynamic) fromJson, Uint8List data) =>
|
||||
fromJson(jsonDecode(utf8.decode(data)));
|
||||
|
||||
Uint8List jsonEncodeBytes(Object? object,
|
||||
{Object? Function(Object?)? toEncodable}) => Uint8List.fromList(
|
||||
utf8.encode(jsonEncode(object, toEncodable: toEncodable)));
|
||||
{Object? Function(Object?)? 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 {
|
||||
final oldObj = fromJson(jsonDecode(utf8.decode(oldBytes)));
|
||||
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>(
|
||||
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(Map<String, dynamic>) fromJsonMap) => (json) => fromJsonMap(json as Map<String, dynamic>);
|
||||
T Function(Map<String, dynamic>) fromJsonMap) =>
|
||||
(json) => fromJsonMap(json! as Map<String, dynamic>);
|
||||
|
@ -3,19 +3,20 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
|
||||
extension BorderExt on Widget {
|
||||
Container debugBorder() => DecoratedBox(
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.redAccent)),
|
||||
child: this);
|
||||
DecoratedBox debugBorder() => DecoratedBox(
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.redAccent)),
|
||||
child: this);
|
||||
}
|
||||
|
||||
extension ModalProgressExt on Widget {
|
||||
BlurryModalProgressHUD withModalHUD(BuildContext context, bool isLoading) => BlurryModalProgressHUD(
|
||||
inAsyncCall: isLoading,
|
||||
blurEffectIntensity: 4,
|
||||
progressIndicator: SpinKitFoldingCube(
|
||||
color: Theme.of(context).highlightColor,
|
||||
size: 90,
|
||||
),
|
||||
color: Theme.of(context).shadowColor,
|
||||
child: this);
|
||||
BlurryModalProgressHUD withModalHUD(BuildContext context, bool isLoading) =>
|
||||
BlurryModalProgressHUD(
|
||||
inAsyncCall: isLoading,
|
||||
blurEffectIntensity: 4,
|
||||
progressIndicator: SpinKitFoldingCube(
|
||||
color: Theme.of(context).highlightColor,
|
||||
size: 90,
|
||||
),
|
||||
color: Theme.of(context).shadowColor,
|
||||
child: this);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import '../tools/tools.dart';
|
||||
import 'veilid_support.dart';
|
||||
|
||||
class DHTRecord {
|
||||
|
||||
DHTRecord(
|
||||
{required VeilidRoutingContext dhtctx,
|
||||
required DHTRecordDescriptor recordDescriptor,
|
||||
@ -46,8 +45,7 @@ class DHTRecord {
|
||||
static Future<DHTRecord> openRead(
|
||||
VeilidRoutingContext dhtctx, TypedKey recordKey,
|
||||
{int defaultSubkey = 0, DHTRecordCrypto? crypto}) async {
|
||||
final recordDescriptor =
|
||||
await dhtctx.openDHTRecord(recordKey, null);
|
||||
final recordDescriptor = await dhtctx.openDHTRecord(recordKey, null);
|
||||
final rec = DHTRecord(
|
||||
dhtctx: dhtctx,
|
||||
recordDescriptor: recordDescriptor,
|
||||
@ -64,8 +62,7 @@ class DHTRecord {
|
||||
int defaultSubkey = 0,
|
||||
DHTRecordCrypto? crypto,
|
||||
}) async {
|
||||
final recordDescriptor =
|
||||
await dhtctx.openDHTRecord(recordKey, writer);
|
||||
final recordDescriptor = await dhtctx.openDHTRecord(recordKey, writer);
|
||||
final rec = DHTRecord(
|
||||
dhtctx: dhtctx,
|
||||
recordDescriptor: recordDescriptor,
|
||||
@ -112,7 +109,7 @@ class DHTRecord {
|
||||
final out = await scopeFunction(this);
|
||||
await close();
|
||||
return out;
|
||||
} catch (_) {
|
||||
} on Exception catch (_) {
|
||||
await delete();
|
||||
rethrow;
|
||||
}
|
||||
@ -128,7 +125,7 @@ class DHTRecord {
|
||||
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 {
|
||||
final data = await get(subkey: subkey, forceRefresh: forceRefresh);
|
||||
if (data == null) {
|
||||
@ -177,17 +174,20 @@ class DHTRecord {
|
||||
} 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,
|
||||
{int subkey = -1}) => eventualWriteBytes(newValue.writeToBuffer(), subkey: subkey);
|
||||
{int subkey = -1}) =>
|
||||
eventualWriteBytes(newValue.writeToBuffer(), subkey: subkey);
|
||||
|
||||
Future<void> eventualUpdateJson<T>(
|
||||
T Function(Map<String, dynamic>) fromJson, Future<T> Function(T) update,
|
||||
{int subkey = -1}) => eventualUpdateBytes(jsonUpdate(fromJson, update), subkey: subkey);
|
||||
T Function(dynamic) fromJson, Future<T> Function(T) update,
|
||||
{int subkey = -1}) =>
|
||||
eventualUpdateBytes(jsonUpdate(fromJson, update), subkey: subkey);
|
||||
|
||||
Future<void> eventualUpdateProtobuf<T extends GeneratedMessage>(
|
||||
T Function(List<int>) fromBuffer, Future<T> Function(T) update,
|
||||
{int subkey = -1}) => eventualUpdateBytes(protobufUpdate(fromBuffer, update),
|
||||
subkey: subkey);
|
||||
T Function(List<int>) fromBuffer, Future<T> Function(T) update,
|
||||
{int subkey = -1}) =>
|
||||
eventualUpdateBytes(protobufUpdate(fromBuffer, update), subkey: subkey);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user