-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
3,602 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 7e9793dee1b85a243edd0e06cb1658e98b077561 | ||
channel: stable | ||
|
||
project_type: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file configures the analyzer, which statically analyzes Dart code to | ||
# check for errors, warnings, and lints. | ||
# | ||
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled | ||
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be | ||
# invoked from the command line by running `flutter analyze`. | ||
|
||
# The following line activates a set of recommended lints for Flutter apps, | ||
# packages, and plugins designed to encourage good coding practices. | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
linter: | ||
# The lint rules applied to this project can be customized in the | ||
# section below to disable rules from the `package:flutter_lints/flutter.yaml` | ||
# included above or to enable additional rules. A list of all available lints | ||
# and their documentation is published at | ||
# https://dart-lang.github.io/linter/lints/index.html. | ||
# | ||
# Instead of disabling a lint rule for the entire project in the | ||
# section below, it can also be suppressed for a single line of code | ||
# or a specific dart file by using the `// ignore: name_of_lint` and | ||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file | ||
# producing the lint. | ||
rules: | ||
# avoid_print: false # Uncomment to disable the `avoid_print` rule | ||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:sqflite_common/sqlite_api.dart'; | ||
import 'package:sqflite_common_ffi/sqflite_ffi.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
const String kDBPath = 'db'; | ||
const String kDBConfigured = 'db_configured'; | ||
|
||
const int kDBVersion = 1; | ||
|
||
void main() { | ||
runApp(const MyApp()); | ||
} | ||
|
||
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( | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
home: const MyHomePage(), | ||
); | ||
} | ||
} | ||
|
||
class MyHomePage extends StatefulWidget { | ||
const MyHomePage({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<MyHomePage> createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
SharedPreferences? prefs; | ||
|
||
Database? db; | ||
|
||
List<Map<String, Object?>>? links; | ||
|
||
Future<bool> dbConfigured() async { | ||
prefs = await SharedPreferences.getInstance(); | ||
return prefs!.getBool(kDBConfigured) ?? false; | ||
} | ||
|
||
Future<void> 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 | ||
) | ||
'''); | ||
} | ||
links = await db?.query('Links') ?? []; | ||
if (kDebugMode) { | ||
print(links); | ||
} | ||
setState(() {}); | ||
} | ||
|
||
Future<void> closeDB() async { | ||
if (db != null && db!.isOpen) { | ||
await db!.close(); | ||
} | ||
} | ||
|
||
Future<bool> addLink( | ||
{required String title, | ||
required String description, | ||
required String url}) async { | ||
await db?.insert('Links', <String, Object?>{ | ||
'title': title, | ||
'description': description, | ||
'url': url | ||
}); | ||
if (await db?.query('Links', where: 'url = ?', whereArgs: [url]) != null) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
Future<void> deleteLink({required String id}) async { | ||
await db?.delete('Links', where: 'id = ?', whereArgs: [id]); | ||
setState(() {}); | ||
} | ||
|
||
Future<void> readDB() async { | ||
links = await db?.query('Links') ?? []; | ||
if (kDebugMode) { | ||
print(links); | ||
} | ||
setState(() {}); | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
openDB(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
closeDB(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Link Management System'), | ||
), | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
if (links != null) ...{ | ||
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('Apri link'), | ||
onPressed: () async { | ||
if (link['url'] != null) { | ||
if (!await launch(link['url'].toString())) { | ||
throw 'Could not launch ${link['url'].toString()}'; | ||
} | ||
} | ||
}, | ||
), | ||
], | ||
)), | ||
), | ||
] | ||
], | ||
) | ||
} | ||
], | ||
), | ||
), | ||
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('Inserisci link'), | ||
content: SingleChildScrollView( | ||
child: ListBody( | ||
children: <Widget>[ | ||
TextField( | ||
decoration: const InputDecoration( | ||
border: OutlineInputBorder(), | ||
labelText: 'Titolo', | ||
), | ||
onChanged: (value) => title = value, | ||
), | ||
const SizedBox(height: 10), | ||
TextField( | ||
decoration: const InputDecoration( | ||
border: OutlineInputBorder(), | ||
labelText: 'Descrizione', | ||
), | ||
onChanged: (value) => description = value, | ||
), | ||
const SizedBox(height: 10), | ||
TextField( | ||
decoration: const InputDecoration( | ||
border: OutlineInputBorder(), | ||
labelText: 'Link della videochiamata', | ||
), | ||
onChanged: (value) => url = value, | ||
), | ||
], | ||
), | ||
), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: Text( | ||
'Annulla', | ||
style: Theme.of(context) | ||
.textTheme | ||
.button! | ||
.copyWith(color: Colors.red), | ||
), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
TextButton( | ||
child: const Text('Salva'), | ||
onPressed: () async { | ||
await addLink( | ||
title: title, description: description, url: url) | ||
.then((value) => readDB()); | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
tooltip: 'Increment', | ||
child: const Icon(Icons.add), | ||
), // This trailing comma makes auto-formatting nicer for build methods. | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flutter/ephemeral |
Oops, something went wrong.