This commit is contained in:
John Smith 2022-03-03 20:45:39 -05:00
parent 7458d0d991
commit 98799b4d3a
20 changed files with 426 additions and 135 deletions

View file

@ -1,51 +1,54 @@
import 'dart:async';
import 'package:logger/logger.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:veilid/veilid.dart';
import 'package:logger_flutter_viewer/logger_flutter_viewer.dart';
import 'package:flutter_loggy/flutter_loggy.dart';
import 'package:loggy/loggy.dart';
// Logger
var stacklog = Logger(
printer: PrettyPrinter(
methodCount: 10,
errorMethodCount: 10,
printTime: true,
colors: true,
printEmojis: true),
output: ScreenOutput());
var log = Logger(
printer: PrettyPrinter(
methodCount: 0,
errorMethodCount: 1,
printTime: true,
colors: true,
printEmojis: true,
noBoxingByDefault: true,
),
output: ScreenOutput());
var barelog = Logger(
printer: PrettyPrinter(
methodCount: 0,
errorMethodCount: 0,
printTime: false,
colors: true,
printEmojis: true,
noBoxingByDefault: true,
),
output: ScreenOutput());
import 'config.dart';
class ScreenOutput extends LogOutput {
@override
void output(OutputEvent event) {
LogConsole.output(event);
}
// Loggy tools
const LogLevel traceLevel = LogLevel('trace', 1);
extension TraceLoggy on Loggy {
void trace(dynamic message, [Object? error, StackTrace? stackTrace]) =>
log(traceLevel, message, error, stackTrace);
}
LogOptions getLogOptions(LogLevel? level) {
return LogOptions(
level ?? LogLevel.all,
stackTraceLevel: LogLevel.error,
);
}
void setRootLogLevel(LogLevel? level) {
Loggy('').level = getLogOptions(level);
}
void initLoggy() {
Loggy.initLoggy(
logPrinter: StreamPrinter(
const PrettyDeveloperPrinter(),
),
logOptions: getLogOptions(null),
);
}
// Entrypoint
void main() {
runApp(const MyApp());
WidgetsFlutterBinding.ensureInitialized();
initLoggy();
runApp(MaterialApp(
title: 'Veilid Plugin Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: const MyApp()));
}
// Main App
@ -56,8 +59,9 @@ class MyApp extends StatefulWidget {
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
class _MyAppState extends State<MyApp> with UiLoggy {
String _veilidVersion = 'Unknown';
Stream<VeilidUpdate>? _updateStream;
@override
void initState() {
@ -75,10 +79,11 @@ class _MyAppState extends State<MyApp> {
} on PlatformException {
veilidVersion = 'Failed to get veilid version.';
}
log.e("Error test");
log.w("Warning test");
stacklog.i("Info test with stacklog");
barelog.d("debug bare-log test");
loggy.error("Error test");
loggy.warning("Warning test");
loggy.info("Info test");
loggy.debug("Debug test");
loggy.trace("Trace test");
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
@ -92,13 +97,70 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
final ButtonStyle buttonStyle =
ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
return Scaffold(
appBar: AppBar(
title: Text('Veilid Plugin Version $_veilidVersion'),
),
body: LogConsole(dark: Theme.of(context).brightness == Brightness.dark),
),
);
body: Column(children: [
Expanded(
child: Container(
color: ThemeData.dark().scaffoldBackgroundColor,
height: MediaQuery.of(context).size.height * 0.4,
child: LoggyStreamWidget(logLevel: loggy.level.logLevel),
)),
Container(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 12),
child: Row(children: [
ElevatedButton(
style: buttonStyle,
onPressed: () async {
//var await Veilid.instance.startupVeilidCore(await getDefaultVeilidConfig())
// setState(() {
// };
},
child: const Text('Startup'),
),
ElevatedButton(
style: buttonStyle,
onPressed: () {},
child: const Text('Shutdown'),
),
])),
Row(children: [
Expanded(
child: TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Debug Command'),
textInputAction: TextInputAction.send,
onSubmitted: (String v) async {
loggy.debug(await Veilid.instance.debug(v));
})),
DropdownButton<LogLevel>(
value: loggy.level.logLevel,
onChanged: (LogLevel? newLevel) {
setState(() {
setRootLogLevel(newLevel);
});
},
items: const [
DropdownMenuItem<LogLevel>(
value: LogLevel.error, child: Text("Error")),
DropdownMenuItem<LogLevel>(
value: LogLevel.warning, child: Text("Warning")),
DropdownMenuItem<LogLevel>(
value: LogLevel.info, child: Text("Info")),
DropdownMenuItem<LogLevel>(
value: LogLevel.debug, child: Text("Debug")),
DropdownMenuItem<LogLevel>(
value: traceLevel, child: Text("Trace")),
DropdownMenuItem<LogLevel>(
value: LogLevel.all, child: Text("All")),
])
]),
]));
}
}