mirror of
https://github.com/wownero/cyberwow.git
synced 2026-10-25 02:08:44 +01:00
null safety 2
This commit is contained in:
@@ -31,9 +31,11 @@ final _theme = ThemeData(
|
||||
primaryColor: crtGreen,
|
||||
hintColor: Colors.yellow,
|
||||
accentColor: crtGreen,
|
||||
cursorColor: crtGreen,
|
||||
backgroundColor: Colors.black,
|
||||
scaffoldBackgroundColor: Colors.black,
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(primary: crtGreen),
|
||||
),
|
||||
textSelectionTheme: TextSelectionThemeData(
|
||||
cursorColor: crtGreen,
|
||||
selectionColor: crtGreen,
|
||||
|
||||
@@ -29,25 +29,18 @@ import '../../../config.dart' as config;
|
||||
import '../../../helper.dart';
|
||||
import '../../../logging.dart';
|
||||
|
||||
Future<http.Response> rpcHTTP(final String method) async {
|
||||
final url = 'http://${config.host}:${config.c.port}/json_rpc';
|
||||
Future<http.Response?> rpcHTTP(final String method) async {
|
||||
final url = Uri.parse('http://${config.host}:${config.c.port}/json_rpc');
|
||||
|
||||
final body = json.encode
|
||||
(
|
||||
{
|
||||
'jsonrpc': '2.0',
|
||||
'method': method,
|
||||
}
|
||||
);
|
||||
final body = json.encode({
|
||||
'jsonrpc': '2.0',
|
||||
'method': method,
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await http.post
|
||||
( url,
|
||||
body: body
|
||||
);
|
||||
final response = await http.post(url, body: body);
|
||||
return response;
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
log.warning(e);
|
||||
return null;
|
||||
}
|
||||
@@ -55,7 +48,7 @@ Future<http.Response> rpcHTTP(final String method) async {
|
||||
|
||||
dynamic jsonDecode(final String responseBody) => json.decode(responseBody);
|
||||
|
||||
Future<dynamic> rpc(final String method, {final String field}) async {
|
||||
Future<dynamic> rpc(final String method, {final String? field}) async {
|
||||
final response = await rpcHTTP(method);
|
||||
|
||||
if (response == null) return null;
|
||||
@@ -73,7 +66,7 @@ Future<dynamic> rpc(final String method, {final String field}) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> rpcString(final String method, {final String field}) async {
|
||||
Future<String> rpcString(final String method, {final String? field}) async {
|
||||
final _field = await rpc(method, field: field);
|
||||
return pretty(_field);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ import '../../../config.dart' as config;
|
||||
import '../../../helper.dart';
|
||||
import '../../../logging.dart';
|
||||
|
||||
Future<http.Response> rpc2(final String method) async {
|
||||
final url = 'http://${config.host}:${config.c.port}/$method';
|
||||
Future<http.Response?> rpc2(final String method) async {
|
||||
final url = Uri.parse('http://${config.host}:${config.c.port}/$method');
|
||||
|
||||
try {
|
||||
final response = await http.post(
|
||||
@@ -46,7 +46,7 @@ Future<http.Response> rpc2(final String method) async {
|
||||
|
||||
dynamic jsonDecode(final String responseBody) => json.decode(responseBody);
|
||||
|
||||
Future<String> rpc2String(final String method, {final String field}) async {
|
||||
Future<String> rpc2String(final String method, {final String? field}) async {
|
||||
final response = await rpc2(method);
|
||||
|
||||
if (response == null) return '';
|
||||
|
||||
@@ -21,20 +21,18 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../../helper.dart';
|
||||
import '../../interface/rpc/rpc.dart';
|
||||
import '../../../config.dart' as config;
|
||||
|
||||
Future<http.Response> syncInfo() => rpc('sync_info');
|
||||
Future<dynamic> syncInfo() => rpc('sync_info');
|
||||
Future<String> syncInfoString() => rpcString('sync_info');
|
||||
|
||||
Future<int> targetHeight() =>
|
||||
rpc('sync_info', field: 'target_height').then(asInt);
|
||||
Future<int> height() => rpc('sync_info', field: 'height').then(asInt);
|
||||
|
||||
Future<http.Response> getInfo() => rpc('get_info');
|
||||
Future<dynamic> getInfo() => rpc('get_info');
|
||||
|
||||
Future<Map<String, dynamic>> getInfoSimple() async {
|
||||
final _getInfo = await rpc('get_info').then(asMap);
|
||||
@@ -55,10 +53,8 @@ Future<List<Map<String, dynamic>>> getConnectionsSimple() async {
|
||||
final _connections =
|
||||
await rpc('get_connections', field: 'connections').then(asJsonArray);
|
||||
|
||||
final _activeConnections =
|
||||
_connections.where(
|
||||
(x) => x['live_time'] > config.c.peerMinimumConnectedTimeInSeconds
|
||||
);
|
||||
final _activeConnections = _connections.where(
|
||||
(x) => x['live_time'] > config.c.peerMinimumConnectedTimeInSeconds);
|
||||
|
||||
final _sortedConn = _activeConnections.toList()
|
||||
..sort((x, y) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import '../../../config.dart' as config;
|
||||
import '../../../logging.dart';
|
||||
import '../../interface/rpc/rpc2.dart' as rpc2;
|
||||
|
||||
Future<http.Response> getTransactionPool() async =>
|
||||
Future<http.Response?> getTransactionPool() async =>
|
||||
rpc2.rpc2('get_transaction_pool');
|
||||
|
||||
Map<String, String> txInOutCache = {};
|
||||
|
||||
@@ -51,15 +51,13 @@ class LNodeApp extends StatelessWidget {
|
||||
title: 'L node',
|
||||
theme: config.c.theme,
|
||||
darkTheme: config.c.theme,
|
||||
home: LNodePage(headline6: 'L node'),
|
||||
home: LNodePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LNodePage extends StatefulWidget {
|
||||
LNodePage({Key key, this.headline6}) : super(key: key);
|
||||
final String headline6;
|
||||
|
||||
LNodePage({Key? key}) : super(key: key);
|
||||
@override
|
||||
_LNodePageState createState() => _LNodePageState();
|
||||
}
|
||||
@@ -68,7 +66,7 @@ class _LNodePageState extends State<LNodePage> with WidgetsBindingObserver {
|
||||
// AppState _state = LoadingState("init...");
|
||||
static const _channel = const MethodChannel('send-intent');
|
||||
|
||||
state.AppState _state;
|
||||
state.AppState? _state;
|
||||
AppLifecycleState _notification = AppLifecycleState.resumed;
|
||||
|
||||
bool _exiting = false;
|
||||
@@ -91,7 +89,7 @@ class _LNodePageState extends State<LNodePage> with WidgetsBindingObserver {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
WidgetsBinding.instance?.removeObserver(this);
|
||||
_inputStreamController.close();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -152,7 +150,7 @@ class _LNodePageState extends State<LNodePage> with WidgetsBindingObserver {
|
||||
super.initState();
|
||||
log.fine("LNodePageState initState");
|
||||
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
WidgetsBinding.instance?.addObserver(this);
|
||||
|
||||
final state.AppHook _appHook = state.AppHook(
|
||||
_setState,
|
||||
@@ -170,7 +168,7 @@ class _LNodePageState extends State<LNodePage> with WidgetsBindingObserver {
|
||||
|
||||
Future<bool> _exitApp(final BuildContext context) async {
|
||||
log.info("LNodePageState _exitApp");
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
WidgetsBinding.instance?.removeObserver(this);
|
||||
|
||||
_exiting = true;
|
||||
_inputStreamController.sink.add('exit');
|
||||
@@ -186,7 +184,7 @@ class _LNodePageState extends State<LNodePage> with WidgetsBindingObserver {
|
||||
Widget build(final BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () => _exitApp(context),
|
||||
child: widget.build(context, _state),
|
||||
child: widget.build(context, _state!),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import '../config.dart' as config;
|
||||
import '../logging.dart';
|
||||
|
||||
import 'prototype.dart';
|
||||
import 'blank.dart';
|
||||
|
||||
class ExitingState extends AppStateAutomata {
|
||||
ExitingState(appHook) : super(appHook);
|
||||
@@ -32,12 +33,12 @@ class ExitingState extends AppStateAutomata {
|
||||
Future<void> wait() async {
|
||||
if (appHook.process != null) {
|
||||
log.fine('exiting state: killing process');
|
||||
appHook.process.kill();
|
||||
await appHook.process.exitCode.timeout(
|
||||
appHook.process?.kill();
|
||||
await appHook.process?.exitCode.timeout(
|
||||
Duration(seconds: config.processKillWaitingInSeconds),
|
||||
onTimeout: () {
|
||||
log.warning('process exitCode timeout');
|
||||
appHook.process.kill(ProcessSignal.sigkill);
|
||||
appHook.process?.kill(ProcessSignal.sigkill);
|
||||
return -1;
|
||||
},
|
||||
);
|
||||
@@ -46,6 +47,6 @@ class ExitingState extends AppStateAutomata {
|
||||
}
|
||||
|
||||
Future<AppStateAutomata> next() async {
|
||||
return null;
|
||||
return BlankState(appHook);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class AppHook {
|
||||
final IsExitingFunc isExiting;
|
||||
final GetInitialIntentFunc getInitialIntent;
|
||||
|
||||
final Process process;
|
||||
final Process? process;
|
||||
final Queue stdout;
|
||||
String stdoutCache;
|
||||
bool processCompleted;
|
||||
@@ -66,7 +66,7 @@ class AppState {
|
||||
if (_isExiting) return true;
|
||||
|
||||
if (appHook.process != null && appHook.processCompleted) {
|
||||
final _exitCode = await appHook.process.exitCode;
|
||||
final _exitCode = await appHook.process?.exitCode;
|
||||
return _exitCode != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -48,7 +49,7 @@ class SyncedState extends AppStateAutomata {
|
||||
|
||||
int height;
|
||||
int pageIndex;
|
||||
PageController pageController;
|
||||
PageController? pageController;
|
||||
|
||||
String getInfoCache = '';
|
||||
String getConnectionsCache = '';
|
||||
@@ -69,10 +70,11 @@ class SyncedState extends AppStateAutomata {
|
||||
}
|
||||
appHook.stdoutCache = _stdoutQueue.join();
|
||||
|
||||
final _stdin = appHook.process.stdin;
|
||||
// ignore: close_sinks
|
||||
final IOSink? _stdin = appHook.process?.stdin;
|
||||
|
||||
_stdin.writeln(x);
|
||||
_stdin.flush();
|
||||
_stdin?.writeln(x);
|
||||
_stdin?.flush();
|
||||
|
||||
syncState();
|
||||
|
||||
|
||||
+14
-7
@@ -31,12 +31,19 @@ import 'widget/exiting.dart' as exiting;
|
||||
|
||||
Widget build(final BuildContext context, final AppState state) {
|
||||
switch (state.runtimeType) {
|
||||
case BlankState: return blank.build(context, state);
|
||||
case LoadingState: return loading.build(context, state);
|
||||
case SyncingState: return syncing.build(context, state);
|
||||
case SyncedState: return synced.build(context, state);
|
||||
case ReSyncingState: return resyncing.build(context, state);
|
||||
case ExitingState: return exiting.build(context, state);
|
||||
default: return Placeholder();
|
||||
case BlankState:
|
||||
return blank.build(context, state as BlankState);
|
||||
case LoadingState:
|
||||
return loading.build(context, state as LoadingState);
|
||||
case SyncingState:
|
||||
return syncing.build(context, state as SyncingState);
|
||||
case SyncedState:
|
||||
return synced.build(context, state as SyncedState);
|
||||
case ReSyncingState:
|
||||
return resyncing.build(context, state as ReSyncingState);
|
||||
case ExitingState:
|
||||
return exiting.build(context, state as ExitingState);
|
||||
default:
|
||||
return Placeholder();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user