Skip to content

Commit

Permalink
Add license dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
DavBfr committed Jul 27, 2023
1 parent fa4a92d commit f0deb90
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 127 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.2.0

- Implement about dialog orientation
- Add license extractor
- Add license dialog

## 2.1.3

- Update dependencies
Expand Down
2 changes: 2 additions & 0 deletions lib/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
export 'src/about.dart';
export 'src/about_content.dart';
export 'src/about_list_title.dart';
export 'src/license_dialog.dart';
export 'src/licenses.dart';
export 'src/licenses_extractor.dart';
export 'src/licenses_list_title.dart';
export 'src/markdown.dart';
export 'src/markdown_list_title.dart';
Expand Down
32 changes: 17 additions & 15 deletions lib/src/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AboutPage extends StatelessWidget {
this.dialog = false,
this.children,
this.values = const {},
this.orientation = Axis.vertical,
}) : super(key: key);

/// The title of the page.
Expand Down Expand Up @@ -106,6 +107,8 @@ class AboutPage extends StatelessWidget {
/// Show a dialog instead of a fullscreen page
final bool dialog;

final Axis orientation;

/// Widgets to add to the dialog box after the name, version, and legalese.
///
/// This could include a link to a Web site, some descriptive text, credits,
Expand Down Expand Up @@ -134,6 +137,7 @@ class AboutPage extends StatelessWidget {
applicationLegalese: applicationLegalese,
applicationDescription: applicationDescription,
values: values,
orientation: orientation,
children: children,
);

Expand All @@ -146,21 +150,17 @@ class AboutPage extends StatelessWidget {
);
}

return SimpleDialog(
title: localTitle,
children: <Widget>[
body,
ButtonBar(
children: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
isCupertino(context)
? 'Close'
: MaterialLocalizations.of(context).closeButtonLabel,
),
),
],
return AlertDialog(
// title: localTitle,
content: body,
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
isCupertino(context)
? 'Close'
: MaterialLocalizations.of(context).closeButtonLabel,
),
),
],
);
Expand Down Expand Up @@ -199,6 +199,7 @@ Future<void> showAboutPage({
bool dialog = false,
List<Widget>? children,
Map<String, String> values = const {},
Axis orientation = Axis.vertical,
}) async {
final page = AboutPage(
title: title,
Expand All @@ -210,6 +211,7 @@ Future<void> showAboutPage({
applicationDescription: applicationDescription,
dialog: dialog,
values: values,
orientation: orientation,
children: children,
);

Expand Down
105 changes: 63 additions & 42 deletions lib/src/about_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AboutContent extends StatefulWidget {
this.applicationDescription,
this.children,
this.values = const {},
this.orientation = Axis.vertical,
}) : super(key: key);

/// The name of the application.
Expand Down Expand Up @@ -97,6 +98,8 @@ class AboutContent extends StatefulWidget {
/// Template replacement values
final Map<String, String> values;

final Axis orientation;

@override
AboutContentState createState() => AboutContentState();
}
Expand All @@ -108,61 +111,79 @@ class AboutContentState extends State<AboutContent> {

final icon = widget.applicationIcon ?? defaultApplicationIcon(context);

final body = <Widget>[];

if (icon != null) {
body.add(const SizedBox(height: 10));
body.add(
IconTheme(data: const IconThemeData(size: 48), child: icon),
);
}

final version = Template(
widget.applicationVersion ?? defaultApplicationVersion(context),
).render(widget.values);

body.add(
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 18),
child: ListBody(
children: <Widget>[
Text(
name,
style: Theme.of(context).textTheme.headlineSmall,
textAlign: TextAlign.center,
final textAlign =
widget.orientation == Axis.vertical ? TextAlign.center : null;

final body = Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 18),
child: ListBody(
children: <Widget>[
Text(
name,
style: Theme.of(context).textTheme.headlineSmall,
textAlign: textAlign,
),
Text(
version,
style: Theme.of(context).textTheme.bodyMedium,
textAlign: textAlign,
),
if (widget.applicationLegalese != null)
Padding(
padding: const EdgeInsets.only(top: 18),
child: Text(
Template(widget.applicationLegalese!).render(widget.values),
style: Theme.of(context).textTheme.bodySmall,
textAlign: textAlign,
),
),
Text(
version,
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
if (widget.applicationDescription != null) ...[
const Divider(),
Container(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: widget.applicationDescription,
),
if (widget.applicationLegalese != null)
Padding(
padding: const EdgeInsets.only(top: 18),
child: Text(
Template(widget.applicationLegalese!).render(widget.values),
style: Theme.of(context).textTheme.bodySmall,
textAlign: TextAlign.center,
),
),
if (widget.applicationDescription != null) const Divider(),
if (widget.applicationDescription != null)
Container(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: widget.applicationDescription,
),
if (widget.applicationDescription != null) const Divider(),
const Divider(),
],
),
],
),
);

if (widget.children != null) {
body.addAll(widget.children!);
if (widget.orientation == Axis.vertical) {
return SingleChildScrollView(
child: ListBody(
children: [
if (icon != null) ...[
const SizedBox(height: 10),
IconTheme(data: const IconThemeData(size: 48), child: icon),
],
body,
if (widget.children != null) ...widget.children!,
],
),
);
}

final themeData = Theme.of(context);

return SingleChildScrollView(
child: ListBody(children: body),
child: ListBody(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (icon != null)
IconTheme(data: themeData.iconTheme, child: icon),
Expanded(child: body),
],
),
if (widget.children != null) ...widget.children!,
],
),
);
}
}
4 changes: 4 additions & 0 deletions lib/src/about_list_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AboutPageListTile extends StatelessWidget {
this.aboutBoxChildren,
this.values = const {},
this.trailing,
this.orientation = Axis.vertical,
}) : super(key: key);

/// The icon to show for this drawer item.
Expand Down Expand Up @@ -132,6 +133,8 @@ class AboutPageListTile extends StatelessWidget {

final Widget? trailing;

final Axis orientation;

@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
Expand Down Expand Up @@ -160,6 +163,7 @@ class AboutPageListTile extends StatelessWidget {
dialog: dialog,
children: aboutBoxChildren,
values: values,
orientation: orientation,
);
},
);
Expand Down
63 changes: 63 additions & 0 deletions lib/src/license_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2019, David PHAM-VAN <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

import 'markdown.dart';

class LicenseDialog extends StatelessWidget {
const LicenseDialog({
Key? key,
required this.text,
}) : super(key: key);

final String text;

@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);
final localizations = MaterialLocalizations.of(context);

return AlertDialog(
content: Padding(
padding: const EdgeInsets.all(8),
child: SizedBox(
width: 500,
child: MarkdownBody(
data: text,
softLineBreak: true,
onTapLink: (text, href, title) =>
const UrlMarkdownTapHandler().onTap(context, text, href, title),
),
),
),
actions: <Widget>[
TextButton(
child: Text(
themeData.useMaterial3
? localizations.closeButtonLabel
: localizations.closeButtonLabel.toUpperCase(),
),
onPressed: () {
Navigator.pop(context);
},
),
],
scrollable: true,
);
}
}
Loading

0 comments on commit f0deb90

Please sign in to comment.