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,23 +17,35 @@ 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(
child: ListView(
children: [
Wrap(
alignment: WrapAlignment.center,
children: [ children: [
_buildMimePie(context, 'images', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('image/')))), _buildMimePie(context, 'images', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('image/')))),
_buildMimePie(context, 'videos', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('video/')))), _buildMimePie(context, 'videos', Map.fromEntries(byMimeTypes.entries.where((kv) => kv.key.startsWith('video/')))),
const Divider(),
Text('Catalogued: ${catalogued.length}'),
Text('With GPS: ${withGps.length}'),
Text('With address: ${located.length}'),
], ],
), ),
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,14 +67,15 @@ 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(
mainAxisSize: MainAxisSize.min,
children: [ children: [
Container( Container(
width: circleDim, width: dim,
height: circleDim, height: dim,
child: Stack( child: Stack(
children: [ children: [
charts.PieChart( charts.PieChart(
@ -82,7 +93,9 @@ class StatsPage extends StatelessWidget {
], ],
), ),
), ),
Column( SizedBox(
width: dim,
child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: seriesData children: seriesData
@ -92,12 +105,14 @@ class StatsPage extends StatelessWidget {
const SizedBox(width: 8), const SizedBox(width: 8),
Text(kv.key), Text(kv.key),
const SizedBox(width: 8), const SizedBox(width: 8),
Text('${kv.value}'), Text('${kv.value}', style: const TextStyle(color: Colors.white70)),
], ],
)) ))
.toList()), .toList()),
),
], ],
); );
});
} }
} }