From 6864d7207a92c335f845efcd6698f4e23795db65 Mon Sep 17 00:00:00 2001 From: Francesco Vezzani <32552589+kekko7072@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:24:01 +0100 Subject: [PATCH] Implemented code snippets on LMS to enable user to create code snippets to copy and use. --- lib/constants.dart | 2 + lib/interfaces/about_page.dart | 38 +++ lib/interfaces/add_widget.dart | 125 +++++++++ lib/interfaces/lms_content_widget.dart | 125 +++++++++ lib/main.dart | 365 ++++--------------------- lib/models/link.dart | 44 --- lib/models/lms_content.dart | 77 ++++++ lib/services/database_local.dart | 100 +++++-- lib/services/imports.dart | 11 +- macos/Podfile.lock | 2 +- pubspec.lock | 20 +- pubspec.yaml | 10 +- 12 files changed, 537 insertions(+), 382 deletions(-) create mode 100644 lib/interfaces/about_page.dart create mode 100644 lib/interfaces/add_widget.dart create mode 100644 lib/interfaces/lms_content_widget.dart delete mode 100644 lib/models/link.dart create mode 100644 lib/models/lms_content.dart diff --git a/lib/constants.dart b/lib/constants.dart index 06fe931..69bdde1 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,2 +1,4 @@ const String kDBPath = 'database_app'; const String kDBConfigured = 'db_configured'; +const int kDBVersion = 7; +const String kDBTable = 'contents'; diff --git a/lib/interfaces/about_page.dart b/lib/interfaces/about_page.dart new file mode 100644 index 0000000..a2922ee --- /dev/null +++ b/lib/interfaces/about_page.dart @@ -0,0 +1,38 @@ +import 'package:about/about.dart'; +import '../services/imports.dart'; + +Future 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: [ + 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'), + ), + ), + )); diff --git a/lib/interfaces/add_widget.dart b/lib/interfaces/add_widget.dart new file mode 100644 index 0000000..5b5e043 --- /dev/null +++ b/lib/interfaces/add_widget.dart @@ -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 createState() => _AddWidgetState(); +} + +class _AddWidgetState extends State { + 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: [ + 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: [ + 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'), + ) + ], + ); + } +} diff --git a/lib/interfaces/lms_content_widget.dart b/lib/interfaces/lms_content_widget.dart new file mode 100644 index 0000000..814d7cb --- /dev/null +++ b/lib/interfaces/lms_content_widget.dart @@ -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 createState() => _LMSContentWidgetState(); +} + +class _LMSContentWidgetState extends State { + @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"); + } + } + }, + ), + ], + ), + )), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index c6626f6..f7ddc8a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,19 +1,8 @@ -import 'package:lms/services/database_local.dart'; import 'package:lms/services/imports.dart'; -import 'package:about/about.dart'; import 'package:flutter/cupertino.dart'; -import 'package:lms/models/link.dart'; -import 'package:url_launcher/url_launcher_string.dart'; - -const int kDBVersion = 1; void main() async { WidgetsFlutterBinding.ensureInitialized(); - PackageInfo packageInfo = await PackageInfo.fromPlatform(); - /*LaunchAtStartup.instance.setup( - appName: packageInfo.appName, - appPath: Platform.resolvedExecutable, - );*/ sqfliteFfiInit(); @@ -23,7 +12,6 @@ void main() async { class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); - // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( @@ -45,81 +33,19 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - bool _isEnabled = false; - SharedPreferences? prefs; - Database? db; - List? links; - - Future dbConfigured() async { - prefs = await SharedPreferences.getInstance(); - return prefs!.getBool(kDBConfigured) ?? false; - } - - Future deleteLink({required String id}) async { - await db?.delete('Links', where: 'id = ?', whereArgs: [id]); - setState(() {}); - } + List? links; - Future readDB() async { - links = Link.fromJson(body: await db?.query('Links')); - if (kDebugMode) { - print('read DB'); - } - setState(() {}); - } - - /*_init() async { - _isEnabled = await launchAtStartup.isEnabled(); - setState(() {}); - } - - _handleEnable() async { - await launchAtStartup.enable(); - await _init(); - } - - _handleDisable() async { - await launchAtStartup.disable(); - await _init(); - }*/ - - /* void _showMaterialDialog() async { - await dbConfigured().then((value) { - if (!_isEnabled && !value) { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Open at login'), - content: const Text('Do you want LMS open at login?'), - actions: [ - TextButton( - onPressed: () async { - await _handleDisable(); - Navigator.of(context).pop(); - }, - child: const Text('No')), - TextButton( - onPressed: () async { - await _handleEnable(); - Navigator.of(context).pop(); - }, - child: const Text('Si'), - ) - ], - ); - }); - } - }); - } -*/ @override void initState() { super.initState(); - //_init(); - openDB(); + DatabaseLocal.open().then((value) { + db = value; + DatabaseLocal(value) + .init() + .then((value) => setState(() => links = value)); + }); } @override @@ -130,234 +56,63 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { - //_showMaterialDialog(); + //DatabaseLocal(db).readDB().then((value) => setState(() => links = value)); + return Scaffold( - appBar: AppBar( - leading: IconButton( - onPressed: () => showAboutApp(), - icon: const Icon(CupertinoIcons.infinite)), - title: GestureDetector( - child: const Text('Link Management System'), - onTap: () => showAboutApp(), - ), - ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - if (links != null && links!.isNotEmpty) ...{ - Wrap( - children: [ - for (var link in links!) ...[ - SizedBox( - width: 300, - child: Card( - child: Column( - children: [ - Stack( - alignment: Alignment.center, - children: [ - Text( - link.title, - style: Theme.of(context).textTheme.titleLarge, - ), - Align( - alignment: Alignment.topRight, - child: IconButton( - onPressed: () async => - await deleteLink(id: link.id.toString()) - .then((value) => readDB()), - icon: const Icon( - Icons.close, - color: Colors.red, - ), - )), - ], - ), - Text( - link.description, - style: Theme.of(context).textTheme.subtitle1, - ), - TextButton( - child: const Text('Open link'), - onPressed: () async { - if (!await launchUrlString(link.url.toString())) { - debugPrint( - 'Could not launch ${link.url.toString()}'); - } - }, - ), - ], - )), - ), - ] - ], - ) - } - ], + appBar: AppBar( + leading: IconButton( + onPressed: () => showAboutApp(context), + icon: const Icon(CupertinoIcons.infinite)), + title: GestureDetector( + child: const Text('Link Management System'), + onTap: () => showAboutApp(context), + ), ), - ), - floatingActionButton: FloatingActionButton( - onPressed: () async => showDialog( - context: context, - barrierDismissible: false, // user must tap button! - builder: (BuildContext context) { - String title = ''; - String description = ''; - String url = ''; - - return AlertDialog( - title: const Text('Insert link'), - content: SingleChildScrollView( - child: ListBody( - children: [ - TextField( - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: 'Title (es. Monday meeting)', - ), - onChanged: (value) => title = value, - ), - const SizedBox(height: 10), - TextField( - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: 'Description (es. Every friday)', - ), - onChanged: (value) => description = value, - ), - const SizedBox(height: 10), - TextField( - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: 'Link (ex. site or meeting)', - ), - onChanged: (value) => url = value, - ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (links != null && links!.isNotEmpty) ...{ + Wrap( + children: [ + for (LMSContent content in links!) ...[ + LMSContentWidget( + lmsContent: content, + onDeleted: () async => await DatabaseLocal(db) + .deleteLink(id: content.id.toString()) + .whenComplete(() => DatabaseLocal(db) + .readDB() + .then((value) => + setState(() => links = value)))) + ] ], - ), - ), - actions: [ - TextButton( - child: Text( - 'Cancel', - style: Theme.of(context) - .textTheme - .button! - .copyWith(color: Colors.red), - ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - TextButton( - child: const Text('Save'), - onPressed: () async => await DatabaseLocal(db) - .addLink(title: title, description: description, url: url) - .then((value) => readDB()) - .whenComplete(() => Navigator.of(context).pop()), - ), - ], - ); - }, + ) + } + ], + ), ), - tooltip: 'Add link', - child: const Icon(Icons.add), - ), - ); - } - - Future openDB() async { - DatabaseFactory databaseFactory = databaseFactoryFfi; - - databaseFactory.setDatabasesPath(kDBPath); - - db = await databaseFactory.openDatabase(kDBPath); - if (kDebugMode) { - print('DB VERSION:'); - print(await db?.getVersion()); - } - - if (await dbConfigured() && await db?.getVersion() == kDBVersion) { - // if (db.getVersion()) expect(await db.getVersion(), 0); - } else { - sqfliteFfiInit(); - await prefs?.setBool('db_configured', true); - - await db?.setVersion(kDBVersion); - - await db?.execute(''' - CREATE TABLE Links ( - id INTEGER PRIMARY KEY, - title TEXT, - description TEXT, - url TEXT - ) - '''); - } - if (kDebugMode) { - print('QUERY FROM DATABASE'); - print(await db?.query('Links')); - print('\n\n'); - } - links = Link.fromJson(body: await db?.query('Links')); - - if (kDebugMode) { - print('first read DB'); - } - setState(() {}); - } - - Future showAboutApp() async => await PackageInfo.fromPlatform() - .then((PackageInfo packageInfo) => showAboutPage( + floatingActionButton: FloatingActionButton( + onPressed: () async => showDialog( context: context, - values: { - 'version': packageInfo.version, - 'year': DateTime.now().year.toString(), + barrierDismissible: false, // user must tap button! + builder: (BuildContext context) { + return AddWidget( + onPressed: (LMSContent content) async => + await DatabaseLocal(db).addLink(content).then((value) { + Navigator.of(context).pop(); + value["success"] + ? EasyLoading.showSuccess(value["message"], + duration: const Duration(seconds: 2)) + : EasyLoading.showError(value["message"], + duration: const Duration(seconds: 5)); + DatabaseLocal(db) + .readDB() + .then((value) => setState(() => links = value)); + })); }, - 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: [ - 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), - ), - /* StatefulBuilder( - builder: (context, setState) => ListTile( - leading: Icon(_isEnabled - ? CupertinoIcons.check_mark_circled - : CupertinoIcons.xmark_circle), - title: const Text('Launch at startup'), - onTap: () async { - if (_isEnabled) { - EasyLoading.showInfo('Disabled launch at startup'); - await launchAtStartup.disable(); - } else { - EasyLoading.showInfo('Enabled launch at startup'); - await launchAtStartup.enable(); - } - setState(() => _isEnabled = !_isEnabled); - }), - ), - */ - ], - applicationIcon: const SizedBox( - width: 100, - height: 100, - child: Image( - image: AssetImage('assets/icon.png'), - ), - ), - )); + ), + tooltip: 'Add link', + child: const Icon(Icons.add), + )); + } } diff --git a/lib/models/link.dart b/lib/models/link.dart deleted file mode 100644 index 634176d..0000000 --- a/lib/models/link.dart +++ /dev/null @@ -1,44 +0,0 @@ -import 'package:flutter/foundation.dart'; - -class Link { - //Ok null safety ma quando serve, questi valori non devono essere null senno la UX non va bene - final int id; - final String title; - final String description; - final String url; - - const Link({ - required this.id, - required this.title, - required this.description, - required this.url, - }); - - //Mapping from Json format to map https://docs.flutter.dev/development/data-and-backend/json - static List fromJson({required List>? body}) { - //1. Creo una lista vuota da usare per poi riempirla e ritornarla con i valori mappari - List list = []; - - //2. Verifico che il body non sia nullo altrimeti potrei avere errori. - if (body != null) { - //3. Ciclo for così ottengo i singoli valori dentro la lista di json file - for (Map value in body) { - if (kDebugMode) { - print('VALUE ${value['id']}'); - print(value); - print('\n'); - } - //4. Aggiungo il singolo link alla lista - list.add(Link( - //Di ogni elemento faccio il cast e metto anche un valore di default se value['key'] mi ritorna nullo - id: value['id'] ?? 0, - title: value['title'] ?? '', - description: value['description'] ?? '', - url: value['url'] ?? '', - )); - } - } - - return list; - } -} diff --git a/lib/models/lms_content.dart b/lib/models/lms_content.dart new file mode 100644 index 0000000..100b84e --- /dev/null +++ b/lib/models/lms_content.dart @@ -0,0 +1,77 @@ +import 'package:flutter/foundation.dart'; + +enum LinkType { url, code } + +class LMSContent { + //Ok null safety ma quando serve, questi valori non devono essere null senno la UX non va bene + final int id; + final String title; + final String description; + final String content; + final LinkType linkType; + + const LMSContent({ + required this.id, + required this.title, + required this.description, + required this.content, + required this.linkType, + }); + + static Map toJson(LMSContent content) { + return { + 'title': content.title, + 'description': content.description, + 'content': content.content, + 'type': content.linkType.toString(), + }; + } + + //Mapping from Json format to map https://docs.flutter.dev/development/data-and-backend/json + static LMSContent fromJson(Map json) { + String linkTypeString = json['type'] ?? 'LinkType.url'; + LinkType linkType = LinkType.url; + + switch (linkTypeString) { + case 'LinkType.url': + linkType = LinkType.url; + break; + case 'LinkType.code': + linkType = LinkType.code; + break; + } + + return LMSContent( + id: json['id'] ?? 0, + title: json['title'] ?? '', + description: json['description'] ?? '', + content: json['content'] ?? '', + linkType: linkType, + ); + } + + //Mapping from Json format to map https://docs.flutter.dev/development/data-and-backend/json + + static List listFromJson( + {required List>? body}) { + //1. Creo una lista vuota da usare per poi riempirla e ritornarla con i valori mappari + List list = []; + + //2. Verifico che il body non sia nullo altrimeti potrei avere errori. + if (body != null) { + //3. Ciclo for così ottengo i singoli valori dentro la lista di json file + for (Map value in body) { + if (kDebugMode) { + print('VALUE ${value['id']}'); + print(value); + print('\n'); + } + + //4. Aggiungo il singolo link alla lista + list.add(LMSContent.fromJson(value)); + } + } + + return list; + } +} diff --git a/lib/services/database_local.dart b/lib/services/database_local.dart index c0018b7..e12a138 100644 --- a/lib/services/database_local.dart +++ b/lib/services/database_local.dart @@ -1,27 +1,95 @@ import 'package:lms/services/imports.dart'; -class DatabaseLocal{ - final Database? db; - DatabaseLocal( this.db); +class DatabaseLocal { + late Database? db; + DatabaseLocal(this.db); + static Future configured() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + return prefs.getBool(kDBConfigured) ?? false; + } + + static Future open() async { + DatabaseFactory databaseFactory = databaseFactoryFfi; + databaseFactory.setDatabasesPath(kDBPath); + + return await databaseFactory.openDatabase(kDBPath); + } + + Future?> init() async { + if (kDebugMode) { + print('DB VERSION:'); + print(await db?.getVersion()); + } + + if (await configured() && await db?.getVersion() == kDBVersion) { + debugPrint("Database already created"); + } else { + debugPrint("Create database"); + sqfliteFfiInit(); + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setBool(kDBConfigured, true); + + try { + await db?.setVersion(kDBVersion); + + await db?.execute(''' + CREATE TABLE $kDBTable ( + id INTEGER PRIMARY KEY, + title TEXT, + description TEXT, + content TEXT, + type TEXT + ) + '''); + } catch (e) { + debugPrint("ERROR DB: $e"); + } + } + if (kDebugMode) { + print('QUERY FROM DATABASE'); + print(await db?.query(kDBTable)); + print('\n\n'); + } + return LMSContent.listFromJson(body: await db?.query(kDBTable)); + } Future closeDB() async { if (db != null && db!.isOpen) { await db!.close(); } } - Future addLink( - {required String title, - required String description, - required String url}) async { - await db?.insert('Links', { - 'title': title, - 'description': description, - 'url': url - }); - if (await db?.query('Links', where: 'url = ?', whereArgs: [url]) != null) { - return true; + + Future> addLink(LMSContent lmsContent) async { + try { + await db?.insert(kDBTable, { + 'title': lmsContent.title, + 'description': lmsContent.description, + 'content': lmsContent.content, + 'type': '${lmsContent.linkType}' + }); + } catch (e) { + debugPrint("ERROR CREATING: $e"); + return {"success": false, "message": "$e"}; + } + if (await db?.query(kDBTable, + where: 'content = ?', whereArgs: [lmsContent.content]) != + null) { + return {"success": true, "message": "Created with success"}; + } else { + debugPrint("Not created"); + return {"success": false, "message": "Error in creation"}; } - return false; } -} \ No newline at end of file + + Future deleteLink({required String id}) async { + await db?.delete(kDBTable, where: 'id = ?', whereArgs: [id]); + } + + Future> readDB() async { + debugPrint('Read table $kDBTable'); + var body = await db?.query(kDBTable); + debugPrint("BODY: $body"); + return LMSContent.listFromJson(body: body); + } +} diff --git a/lib/services/imports.dart b/lib/services/imports.dart index c2b3f96..0d922ce 100644 --- a/lib/services/imports.dart +++ b/lib/services/imports.dart @@ -1,7 +1,7 @@ export 'dart:io'; export 'package:flutter/foundation.dart'; +export 'package:flutter/services.dart'; -//export 'package:launch_at_startup/launch_at_startup.dart'; export 'package:sqflite_common/sqlite_api.dart'; export 'package:sqflite_common_ffi/sqflite_ffi.dart'; export 'package:shared_preferences/shared_preferences.dart'; @@ -9,5 +9,14 @@ export 'package:url_launcher/url_launcher.dart'; export 'package:package_info_plus/package_info_plus.dart'; export 'package:flutter/material.dart'; export 'package:flutter_easyloading/flutter_easyloading.dart'; +export 'package:url_launcher/url_launcher_string.dart'; export 'package:lms/constants.dart'; + +export '../interfaces/add_widget.dart'; +export '../interfaces/about_page.dart'; +export '../interfaces/lms_content_widget.dart'; + +export '../models/lms_content.dart'; + +export '../services/database_local.dart'; diff --git a/macos/Podfile.lock b/macos/Podfile.lock index c200488..7f39409 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -44,4 +44,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7 -COCOAPODS: 1.11.3 +COCOAPODS: 1.12.0 diff --git a/pubspec.lock b/pubspec.lock index cf74d09..8227105 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -236,10 +236,10 @@ packages: dependency: transitive description: name: image - sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6" + sha256: "483a389d6ccb292b570c31b3a193779b1b0178e7eb571986d9a49904b6861227" url: "https://pub.dev" source: hosted - version: "3.3.0" + version: "4.0.15" intersperse: dependency: transitive description: @@ -316,10 +316,10 @@ packages: dependency: "direct dev" description: name: msix - sha256: e3de4d9f52543ad6e4b0f534991e1303cbd379d24be28dd241ac60bd9439a201 + sha256: "765e6b4d9f571956014d85062614468993d9e4b998bb57f2b727845b6d99c6f1" url: "https://pub.dev" source: hosted - version: "3.7.0" + version: "3.8.2" package_config: dependency: transitive description: @@ -332,10 +332,10 @@ packages: dependency: "direct main" description: name: package_info_plus - sha256: f619162573096d428ccde2e33f92e05b5a179cd6f0e3120c1005f181bee8ed16 + sha256: "8df5ab0a481d7dc20c0e63809e90a588e496d276ba53358afc4c4443d0a00697" url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" package_info_plus_platform_interface: dependency: transitive description: @@ -428,10 +428,10 @@ packages: dependency: "direct main" description: name: shared_preferences - sha256: "5949029e70abe87f75cfe59d17bf5c397619c4b74a099b10116baeb34786fad9" + sha256: ee6257848f822b8481691f20c3e6d2bfee2e9eccb2a3d249907fcfb198c55b41 url: "https://pub.dev" source: hosted - version: "2.0.17" + version: "2.0.18" shared_preferences_android: dependency: transitive description: @@ -585,10 +585,10 @@ packages: dependency: "direct main" description: name: url_launcher - sha256: e8f2efc804810c0f2f5b485f49e7942179f56eabcfe81dce3387fec4bb55876b + sha256: "75f2846facd11168d007529d6cd8fcb2b750186bea046af9711f10b907e1587e" url: "https://pub.dev" source: hosted - version: "6.1.9" + version: "6.1.10" url_launcher_android: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8e5a4ee..bac2fe0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Link Management System publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.2+4 +version: 0.0.3+5 environment: sdk: ">=2.16.1 <3.0.0" @@ -14,10 +14,10 @@ dependencies: cupertino_icons: ^1.0.5 sqflite_common_ffi: ^2.2.1+1 - shared_preferences: ^2.0.17 - url_launcher: ^6.1.9 + shared_preferences: ^2.0.18 + url_launcher: ^6.1.10 about: ^2.1.1 - package_info_plus: ^3.0.2 + package_info_plus: ^3.0.3 adaptive_dialog: ^1.8.2 #launch_at_startup: ^0.2.1 #auto_updater: ^0.1.6 NEED ADDITIONAL REQUIREMENT @@ -28,7 +28,7 @@ dev_dependencies: sdk: flutter flutter_lints: ^2.0.1 - msix: ^3.7.0 + msix: ^3.8.2 msix_config: display_name: LMS