Skip to content

Commit

Permalink
Implemented code snippets on LMS to enable user to create code snippe…
Browse files Browse the repository at this point in the history
…ts to copy and use.
  • Loading branch information
kekko7072 committed Mar 1, 2023
1 parent e3c2b05 commit 6864d72
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 382 deletions.
2 changes: 2 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const String kDBPath = 'database_app';
const String kDBConfigured = 'db_configured';
const int kDBVersion = 7;
const String kDBTable = 'contents';
38 changes: 38 additions & 0 deletions lib/interfaces/about_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:about/about.dart';
import '../services/imports.dart';

Future<void> showAboutApp(BuildContext context) async =>
await PackageInfo.fromPlatform()
.then((PackageInfo packageInfo) => showAboutPage(
context: context,
values: {
'version': packageInfo.version,
'year': DateTime.now().year.toString(),
},
applicationLegalese:
'Copyright © Simone Porcari | Riccardo Rettore | Francesco Vezzani, {{ year }}',
applicationDescription: const Text(
'Make managing your links quick and easy!\n\nThe Link Management System app makes it easy to store and manage all of your important links.\nManage your entire link library with the app’s intuitive organisation system, which allows you to quickly find and open links by description or title.'),
children: <Widget>[
const MarkdownPageListTile(
icon: Icon(Icons.list),
title: Text('Changelog'),
filename: 'CHANGELOG.md',
),
const MarkdownPageListTile(
icon: Icon(Icons.logo_dev),
title: Text('Contributing'),
filename: 'CONTRIBUTING.md',
),
const LicensesPageListTile(
icon: Icon(Icons.favorite),
),
],
applicationIcon: const SizedBox(
width: 100,
height: 100,
child: Image(
image: AssetImage('assets/icon.png'),
),
),
));
125 changes: 125 additions & 0 deletions lib/interfaces/add_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import 'package:lms/services/imports.dart';

class AddWidget extends StatefulWidget {
const AddWidget({Key? key, required this.onPressed}) : super(key: key);
final Function(LMSContent content) onPressed;

@override
State<AddWidget> createState() => _AddWidgetState();
}

class _AddWidgetState extends State<AddWidget> {
String title = '';
String description = '';
String url = '';
LinkType linkType = LinkType.code;

@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Insert content'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ActionChip(
elevation: 2.0,
padding: const EdgeInsets.all(5.0),
avatar: Icon(
Icons.code,
color:
linkType == LinkType.code ? Colors.white : Colors.pink,
),
label: Text(
'Code',
style: TextStyle(
color: linkType == LinkType.code
? Colors.white
: Colors.pink),
),
onPressed: () => setState(() => linkType = LinkType.code),
backgroundColor:
linkType == LinkType.code ? Colors.pink : Colors.white,
),
ActionChip(
elevation: 2.0,
padding: const EdgeInsets.all(5.0),
avatar: Icon(
Icons.link,
color:
linkType == LinkType.url ? Colors.white : Colors.pink,
),
label: Text(
'Url',
style: TextStyle(
color: linkType == LinkType.url
? Colors.white
: Colors.pink),
),
onPressed: () => setState(() => linkType = LinkType.url),
backgroundColor:
linkType == LinkType.url ? Colors.pink : Colors.white,
),
],
),
const SizedBox(height: 20),
TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Title (es. Monday meeting)',
),
onChanged: (value) => title = value,
),
const SizedBox(height: 10),
TextField(
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText:
'Description (ex. ${linkType == LinkType.code ? "Create new file" : "Every friday"})',
),
onChanged: (value) => description = value,
),
const SizedBox(height: 10),
TextField(
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: linkType == LinkType.code
? 'Code (ex. sudo apt install)'
: 'Link (ex. site or meeting)',
),
minLines: linkType == LinkType.code ? 2 : 1,
maxLines: linkType == LinkType.code ? 5 : 2,
onChanged: (value) => url = value,
),
],
),
),
actions: <Widget>[
TextButton(
child: Text(
'Cancel',
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(color: Colors.red),
),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
onPressed: () async => await widget.onPressed(LMSContent(
id: 0,
title: title,
description: description,
content: url,
linkType: linkType,
)),
child: const Text('Save'),
)
],
);
}
}
125 changes: 125 additions & 0 deletions lib/interfaces/lms_content_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import 'package:lms/services/imports.dart';

class LMSContentWidget extends StatefulWidget {
const LMSContentWidget(
{Key? key, required this.lmsContent, required this.onDeleted})
: super(key: key);
final LMSContent lmsContent;
final Function onDeleted;

@override
State<LMSContentWidget> createState() => _LMSContentWidgetState();
}

class _LMSContentWidgetState extends State<LMSContentWidget> {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 250 + widget.lmsContent.title.characters.length * 10,
child: Card(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 10),
child: Column(
children: [
Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.topLeft,
child: ActionChip(
padding: const EdgeInsets.all(5.0),
avatar: Icon(
widget.lmsContent.linkType == LinkType.url
? Icons.link
: Icons.code,
color: Colors.white,
),
label: Text(
widget.lmsContent.linkType == LinkType.url
? "Url"
: 'Code',
style: const TextStyle(color: Colors.white),
),
onPressed: () {},
backgroundColor: Colors.pink,
),
),
Text(
widget.lmsContent.title,
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
Align(
alignment: Alignment.topRight,
child: IconButton(
onPressed: () async => await widget.onDeleted(),
icon: const Icon(
Icons.close,
color: Colors.red,
),
)),
],
),
Text(
widget.lmsContent.description,
style: Theme.of(context).textTheme.titleMedium,
),
if (widget.lmsContent.linkType == LinkType.code) ...[
SelectableText(
widget.lmsContent.content,
style: const TextStyle(
color: Colors.pink,
fontWeight: FontWeight.bold,
fontSize: 25),
textAlign: TextAlign.center,
onTap: () async {
await Clipboard.setData(
ClipboardData(text: widget.lmsContent.content));
EasyLoading.showSuccess("Code copied");
},
contextMenuBuilder: (context, editableTextState) =>
const AlertDialog(),
showCursor: true,
cursorWidth: 2,
cursorColor: Colors.red,
cursorRadius: const Radius.circular(5),
),
] else if (widget.lmsContent.linkType == LinkType.url) ...[
///NEW
],
const SizedBox(height: 5),
TextButton(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.lmsContent.linkType == LinkType.code) ...[
const Icon(Icons.copy),
const SizedBox(width: 5),
const Text('Copy code'),
] else if (widget.lmsContent.linkType == LinkType.url) ...[
const Icon(Icons.link),
const SizedBox(width: 5),
const Text('Open url'),
],
],
),
onPressed: () async {
if (widget.lmsContent.linkType == LinkType.code) {
await Clipboard.setData(
ClipboardData(text: widget.lmsContent.content));
EasyLoading.showSuccess("Code copied");
} else if (widget.lmsContent.linkType == LinkType.url) {
try {
await launchUrlString(widget.lmsContent.content);
} catch (e) {
EasyLoading.showError("Error launching url");
}
}
},
),
],
),
)),
);
}
}
Loading

0 comments on commit 6864d72

Please sign in to comment.