stats: fixed layout

This commit is contained in:
Thibault Deckers 2020-03-21 10:03:53 +09:00
parent 7e3ab2bd2e
commit 901f2a07b9

View file

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:aves/model/collection_lens.dart'; import 'package:aves/model/collection_lens.dart';
import 'package:aves/model/image_entry.dart'; import 'package:aves/model/image_entry.dart';
import 'package:aves/utils/color_utils.dart'; import 'package:aves/utils/color_utils.dart';
@ -19,22 +17,34 @@ class StatsPage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final catalogued = entries.where((entry) => entry.isCatalogued); final catalogued = entries.where((entry) => entry.isCatalogued);
final withGps = catalogued.where((entry) => entry.hasGps); final withGps = catalogued.where((entry) => entry.hasGps);
final located = withGps.where((entry) => entry.isLocated);
final Map<String, int> byMimeTypes = groupBy(entries, (entry) => entry.mimeType).map((k, v) => MapEntry(k, v.length)); final Map<String, int> byMimeTypes = groupBy(entries, (entry) => entry.mimeType).map((k, v) => MapEntry(k, v.length));
return MediaQueryDataProvider( return MediaQueryDataProvider(
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Stats'), title: const Text('Stats'),
), ),
body: ListView( body: SafeArea(
children: [ child: ListView(
_buildMimePie(context, 'images', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('image/')))), children: [
_buildMimePie(context, 'videos', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('video/')))), Wrap(
const Divider(), alignment: WrapAlignment.center,
Text('Catalogued: ${catalogued.length}'), children: [
Text('With GPS: ${withGps.length}'), _buildMimePie(context, 'images', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('image/')))),
Text('With address: ${located.length}'), _buildMimePie(context, 'videos', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('video/')))),
], ],
),
Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
LinearProgressIndicator(value: withGps.length / entries.length),
const SizedBox(height: 8),
Text('${withGps.length} entries with location'),
],
),
),
],
),
), ),
), ),
); );
@ -57,47 +67,52 @@ class StatsPage extends StatelessWidget {
), ),
]; ];
final size = MediaQuery.of(context).size; return LayoutBuilder(builder: (context, constraints) {
final circleDim = min(size.width, size.height) / 2; var mq = MediaQuery.of(context);
final dim = constraints.maxWidth / (mq.orientation == Orientation.portrait ? 2 : 4);
return Row( return Row(
children: [ mainAxisSize: MainAxisSize.min,
Container( children: [
width: circleDim, Container(
height: circleDim, width: dim,
child: Stack( height: dim,
children: [ child: Stack(
charts.PieChart( children: [
series, charts.PieChart(
defaultRenderer: charts.ArcRendererConfig( series,
arcWidth: 16, defaultRenderer: charts.ArcRendererConfig(
arcWidth: 16,
),
), ),
), Center(
Center( child: Text(
child: Text( '${byMimeTypes.values.fold(0, (prev, v) => prev + v)}\n$label',
'${byMimeTypes.values.fold(0, (prev, v) => prev + v)}\n$label', textAlign: TextAlign.center,
textAlign: TextAlign.center, ),
), ),
), ],
], ),
), ),
), SizedBox(
Column( width: dim,
mainAxisAlignment: MainAxisAlignment.center, child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center,
children: seriesData crossAxisAlignment: CrossAxisAlignment.start,
.map((kv) => Row( children: seriesData
children: [ .map((kv) => Row(
Icon(Icons.fiber_manual_record, color: stringToColor(kv.key)), children: [
const SizedBox(width: 8), Icon(Icons.fiber_manual_record, color: stringToColor(kv.key)),
Text(kv.key), const SizedBox(width: 8),
const SizedBox(width: 8), Text(kv.key),
Text('${kv.value}'), const SizedBox(width: 8),
], Text('${kv.value}', style: const TextStyle(color: Colors.white70)),
)) ],
.toList()), ))
], .toList()),
); ),
],
);
});
} }
} }