lint work

This commit is contained in:
Christien Rioux 2023-07-26 14:20:29 -04:00
parent 9e4008214d
commit 6e8725f569
43 changed files with 257 additions and 332 deletions

View file

@ -1,7 +1,8 @@
import 'dart:io';
import 'package:window_manager/window_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
Future<void> setupDesktopWindow() async {
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
@ -15,7 +16,7 @@ Future<void> setupDesktopWindow() async {
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});

View file

@ -4,18 +4,17 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
// Caches a state value which can be changed from anywhere
// Creates a provider interface that notices when the value changes
class ExternalStreamState<T> {
T currentState;
StreamController<T> streamController;
ExternalStreamState(T initialState)
: currentState = initialState,
streamController = StreamController<T>.broadcast();
T currentState;
StreamController<T> streamController;
void add(T newState) {
currentState = newState;
streamController.add(newState);
}
AutoDisposeStreamProvider<T> provider() {
return AutoDisposeStreamProvider<T>((ref) async* {
AutoDisposeStreamProvider<T> provider() => AutoDisposeStreamProvider<T>((ref) async* {
if (await streamController.stream.isEmpty) {
yield currentState;
}
@ -23,5 +22,4 @@ class ExternalStreamState<T> {
yield value;
}
});
}
}

View file

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

View file

@ -265,9 +265,9 @@ const _byteToPhono = [
Map<String, int> _phonoToByte = _buildPhonoToByte();
Map<String, int> _buildPhonoToByte() {
Map<String, int> phonoToByte = {};
for (int b = 0; b < 256; b++) {
String ph = _byteToPhono[b];
final phonoToByte = <String, int>{};
for (var b = 0; b < 256; b++) {
final ph = _byteToPhono[b];
phonoToByte[ph] = b;
}
return phonoToByte;
@ -278,10 +278,10 @@ String prettyPhonoString(String s,
assert(wordsPerLine >= 1);
assert(phonoPerWord >= 1);
final cs = canonicalPhonoString(s).toUpperCase();
String out = "";
int words = 0;
int phonos = 0;
for (int i = 0; i < cs.length; i += 3) {
var out = '';
var words = 0;
var phonos = 0;
for (var i = 0; i < cs.length; i += 3) {
if (i != 0) {
phonos += 1;
if (phonos == phonoPerWord) {
@ -289,9 +289,9 @@ String prettyPhonoString(String s,
words += 1;
if (words == wordsPerLine) {
words = 0;
out += "\n";
out += '\n';
} else {
out += " ";
out += ' ';
}
}
}
@ -301,22 +301,22 @@ String prettyPhonoString(String s,
}
String canonicalPhonoString(String s) {
Uint8List bytes = Uint8List.fromList(utf8.encode(s.toLowerCase()));
String cs = "";
for (int i = 0; i < bytes.length; i++) {
int ch = bytes[i];
final bytes = Uint8List.fromList(utf8.encode(s.toLowerCase()));
var cs = '';
for (var i = 0; i < bytes.length; i++) {
final ch = bytes[i];
if (ch >= $a && ch <= $z) {
cs += String.fromCharCode(ch);
}
}
if (cs.length % 3 != 0) {
throw const FormatException(
"phonobyte string length should be a multiple of 3");
'phonobyte string length should be a multiple of 3');
}
for (int i = 0; i < cs.length; i += 3) {
String ph = cs.substring(i, i + 3);
for (var i = 0; i < cs.length; i += 3) {
final ph = cs.substring(i, i + 3);
if (!_phonoToByte.containsKey(ph)) {
throw const FormatException("phonobyte string contains invalid sequence");
throw const FormatException('phonobyte string contains invalid sequence');
}
}
return cs;
@ -325,17 +325,17 @@ String canonicalPhonoString(String s) {
Uint8List decodePhono(String s) {
final cs = canonicalPhonoString(s);
final out = Uint8List(cs.length ~/ 3);
for (int i = 0; i < cs.length; i += 3) {
String ph = cs.substring(i, i + 3);
int b = _phonoToByte[ph]!;
for (var i = 0; i < cs.length; i += 3) {
final ph = cs.substring(i, i + 3);
final b = _phonoToByte[ph]!;
out[i] = b;
}
return out;
}
String encodePhono(Uint8List b) {
String out = "";
for (int i = 0; i < b.length; i++) {
var out = '';
for (var i = 0; i < b.length; i++) {
out += _byteToPhono[b[i]];
}
return out;

View file

@ -1,19 +1,16 @@
import 'package:protobuf/protobuf.dart';
import 'dart:typed_data';
import 'package:protobuf/protobuf.dart';
Future<Uint8List> protobufUpdateBytes<T extends GeneratedMessage>(
T Function(List<int>) fromBuffer,
Uint8List oldBytes,
Future<T> Function(T) update) async {
T oldObj = fromBuffer(oldBytes);
T newObj = await update(oldObj);
final oldObj = fromBuffer(oldBytes);
final newObj = await update(oldObj);
return Uint8List.fromList(newObj.writeToBuffer());
}
Future<Uint8List> Function(Uint8List)
protobufUpdate<T extends GeneratedMessage>(
T Function(List<int>) fromBuffer, Future<T> Function(T) update) {
return (Uint8List oldBytes) {
return protobufUpdateBytes(fromBuffer, oldBytes, update);
};
}
T Function(List<int>) fromBuffer, Future<T> Function(T) update) => (oldBytes) => protobufUpdateBytes(fromBuffer, oldBytes, update);

View file

@ -1,6 +1,6 @@
export 'desktop_control.dart';
export 'external_stream_state.dart';
export 'json_tools.dart';
export 'phono_byte.dart';
export 'protobuf_tools.dart';
export 'widget_helpers.dart';
export 'desktop_control.dart';

View file

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