Add some version into to about page, and log level changer.

This commit is contained in:
Dain Nilsson 2021-11-24 11:38:30 +01:00
parent e439acdce6
commit cc1426caf1
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
4 changed files with 180 additions and 6 deletions

View File

@ -1,19 +1,50 @@
import 'package:flutter/material.dart';
import 'dart:io';
class AboutPage extends StatelessWidget {
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:yubico_authenticator/core/state.dart';
final log = Logger('about');
class AboutPage extends ConsumerWidget {
const AboutPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final rpcState = ref.watch(rpcStateProvider);
return Scaffold(
appBar: AppBar(
title: const Text('About Yubico Authenticator'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text('About placeholder'),
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('ykman version: ${rpcState.version}'),
Text('Dart version: ${Platform.version}'),
const SizedBox(height: 8.0),
Text('Log level: ${ref.watch(logLevelProvider)}'),
Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
ref.read(logLevelProvider.notifier).setLevel(Level.INFO);
log.info('Log level changed to INFO');
},
child: const Text('INFO'),
),
TextButton(
onPressed: () {
ref.read(logLevelProvider.notifier).setLevel(Level.CONFIG);
log.config('Log level changed to CONFIG');
},
child: const Text('DEBUG'),
),
],
),
],
),
),

View File

@ -30,3 +30,8 @@ class RpcResponse with _$RpcResponse {
factory RpcResponse.fromJson(Map<String, dynamic> json) =>
_$RpcResponseFromJson(json);
}
@freezed
class RpcState with _$RpcState {
const factory RpcState(String version) = _RpcState;
}

View File

@ -796,3 +796,125 @@ abstract class RpcError implements RpcResponse {
$RpcErrorCopyWith<RpcError> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
class _$RpcStateTearOff {
const _$RpcStateTearOff();
_RpcState call(String version) {
return _RpcState(
version,
);
}
}
/// @nodoc
const $RpcState = _$RpcStateTearOff();
/// @nodoc
mixin _$RpcState {
String get version => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$RpcStateCopyWith<RpcState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $RpcStateCopyWith<$Res> {
factory $RpcStateCopyWith(RpcState value, $Res Function(RpcState) then) =
_$RpcStateCopyWithImpl<$Res>;
$Res call({String version});
}
/// @nodoc
class _$RpcStateCopyWithImpl<$Res> implements $RpcStateCopyWith<$Res> {
_$RpcStateCopyWithImpl(this._value, this._then);
final RpcState _value;
// ignore: unused_field
final $Res Function(RpcState) _then;
@override
$Res call({
Object? version = freezed,
}) {
return _then(_value.copyWith(
version: version == freezed
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
abstract class _$RpcStateCopyWith<$Res> implements $RpcStateCopyWith<$Res> {
factory _$RpcStateCopyWith(_RpcState value, $Res Function(_RpcState) then) =
__$RpcStateCopyWithImpl<$Res>;
@override
$Res call({String version});
}
/// @nodoc
class __$RpcStateCopyWithImpl<$Res> extends _$RpcStateCopyWithImpl<$Res>
implements _$RpcStateCopyWith<$Res> {
__$RpcStateCopyWithImpl(_RpcState _value, $Res Function(_RpcState) _then)
: super(_value, (v) => _then(v as _RpcState));
@override
_RpcState get _value => super._value as _RpcState;
@override
$Res call({
Object? version = freezed,
}) {
return _then(_RpcState(
version == freezed
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$_RpcState implements _RpcState {
const _$_RpcState(this.version);
@override
final String version;
@override
String toString() {
return 'RpcState(version: $version)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _RpcState &&
(identical(other.version, version) || other.version == version));
}
@override
int get hashCode => Object.hash(runtimeType, version);
@JsonKey(ignore: true)
@override
_$RpcStateCopyWith<_RpcState> get copyWith =>
__$RpcStateCopyWithImpl<_RpcState>(this, _$identity);
}
abstract class _RpcState implements RpcState {
const factory _RpcState(String version) = _$_RpcState;
@override
String get version;
@override
@JsonKey(ignore: true)
_$RpcStateCopyWith<_RpcState> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -15,6 +15,22 @@ final rpcProvider = Provider<RpcSession>((ref) {
throw UnimplementedError();
});
final rpcStateProvider = StateNotifierProvider<RpcStateNotifier, RpcState>(
(ref) => RpcStateNotifier(ref.watch(rpcProvider)));
class RpcStateNotifier extends StateNotifier<RpcState> {
final RpcSession rpc;
RpcStateNotifier(this.rpc) : super(const RpcState('unknown')) {
_init();
}
_init() async {
final response = await rpc.command('get', []);
if (mounted) {
state = state.copyWith(version: response['data']['version']);
}
}
}
final logLevelProvider = StateNotifierProvider<LogLevelNotifier, Level>(
(ref) => LogLevelNotifier(ref.watch(rpcProvider), Logger.root.level));