import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'translation.dart'; /// Group all distinct notices by component, removing exact duplicates. Future>> collectLicenseNotices( Stream entries, ) async { final notices = >{}; 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, () => {}).add(text); } } return notices; } class OpenSourceLicenses extends StatefulWidget { const OpenSourceLicenses({super.key}); @override State createState() => _OpenSourceLicensesState(); } class _OpenSourceLicensesState extends State { late final notices = collectLicenseNotices(LicenseRegistry.licenses); @override Widget build(BuildContext context) => Scaffold( appBar: AppBar(title: const CopyText('Open-source licenses')), body: FutureBuilder>>( 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), ), ], ), ), ], ); }, ), ); }