Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kekko7072 committed Mar 9, 2022
1 parent 34b9c70 commit f504c88
Show file tree
Hide file tree
Showing 63 changed files with 3,602 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .gitignore
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
10 changes: 10 additions & 0 deletions .metadata
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
29 changes: 29 additions & 0 deletions analysis_options.yaml
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
267 changes: 267 additions & 0 deletions lib/main.dart
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.
);
}
}
1 change: 1 addition & 0 deletions linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flutter/ephemeral
Loading

0 comments on commit f504c88

Please sign in to comment.