Prepare Android release and refine bookshelf
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'translation.dart';
|
||||
|
||||
/// Group all distinct notices by component, removing exact duplicates.
|
||||
Future<Map<String, Set<String>>> collectLicenseNotices(
|
||||
Stream<LicenseEntry> entries,
|
||||
) async {
|
||||
final notices = <String, Set<String>>{};
|
||||
await for (final entry in entries) {
|
||||
final text = entry.paragraphs.map((p) => p.text).join('\n\n').trim();
|
||||
if (text.isEmpty) continue;
|
||||
for (final package in entry.packages.toSet()) {
|
||||
notices.putIfAbsent(package, () => <String>{}).add(text);
|
||||
}
|
||||
}
|
||||
return notices;
|
||||
}
|
||||
|
||||
class OpenSourceLicenses extends StatefulWidget {
|
||||
const OpenSourceLicenses({super.key});
|
||||
|
||||
@override
|
||||
State<OpenSourceLicenses> createState() => _OpenSourceLicensesState();
|
||||
}
|
||||
|
||||
class _OpenSourceLicensesState extends State<OpenSourceLicenses> {
|
||||
late final notices = collectLicenseNotices(LicenseRegistry.licenses);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const CopyText('Open-source licenses')),
|
||||
body: FutureBuilder<Map<String, Set<String>>>(
|
||||
future: notices,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return const Center(child: CopyText('Licenses could not be loaded.'));
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final entries = snapshot.data!.entries.toList()
|
||||
..sort((a, b) => a.key.toLowerCase().compareTo(b.key.toLowerCase()));
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
const CopyText(
|
||||
'Lumen uses open-source software and fonts. Choose a component to read its notices.',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
for (final entry in entries)
|
||||
Card(
|
||||
child: ExpansionTile(
|
||||
title: Text(entry.key),
|
||||
subtitle: const CopyText('View license notice'),
|
||||
children: [
|
||||
for (final notice in entry.value)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SelectableText(notice),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user