|
|
@ -1,24 +1,21 @@ |
|
|
|
# Package |
|
|
|
# Package |
|
|
|
|
|
|
|
|
|
|
|
Package can be used to organize and share a set of functions in Dart. It is simply a sharable library or modules. |
|
|
|
Package can be used to organize and share a set of functions in Dart. It is simply a sharable library or modules. |
|
|
|
Package is similar to Dart Application except that Dart Package does not have application entry point - main. |
|
|
|
Package is similar to Dart Application except that Dart Package does not have application entry point - `main`. |
|
|
|
A minimal package consists of the following: |
|
|
|
A minimal package consists of the following: |
|
|
|
|
|
|
|
|
|
|
|
- pubspec.yaml: |
|
|
|
- `pubspec.yaml`: a metadata file that declares the package name, version, author, etc. |
|
|
|
A metadata file that declares the package name, version, author, etc. |
|
|
|
- `lib/`: a directory contains the public code of the package, at least one dart file. |
|
|
|
- lib: |
|
|
|
|
|
|
|
The lib directory contains the public code of the package, at least one .dart file. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Instructions: |
|
|
|
### Instructions: |
|
|
|
|
|
|
|
|
|
|
|
Create a Flutter package for your Secure Notes app. You should write |
|
|
|
Create a Flutter package for your [Secure Notes app](../secure-notes/README.md). |
|
|
|
your own package which will work with sqflite and have CRUD |
|
|
|
You should write your own package which will work with [`sqflite`](https://pub.dev/packages/sqflite) and have CRUD functionality. |
|
|
|
functionality. |
|
|
|
Your package should consist of `Database` class and `Note` class which will allow easy access to SQLite database. |
|
|
|
Your package should consist of Database.dart class and Note class which |
|
|
|
|
|
|
|
will allow easy access to SQLite database. |
|
|
|
|
|
|
|
In the end you should be able to import it like: |
|
|
|
In the end you should be able to import it like: |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
```dart |
|
|
|
import 'package:note/note.dart'; |
|
|
|
import 'package:note/note.dart'; |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
@ -31,7 +28,7 @@ import 'package:note/note.dart'; |
|
|
|
|
|
|
|
|
|
|
|
### Database.dart |
|
|
|
### Database.dart |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
```dart |
|
|
|
class Database { |
|
|
|
class Database { |
|
|
|
Database _db; |
|
|
|
Database _db; |
|
|
|
|
|
|
|
|
|
|
@ -45,26 +42,26 @@ Database _db; |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Example of Database class, where you should create table "Note" with 4 parameters : |
|
|
|
Example of Database class, where you should create table `Note` with 4 parameters: |
|
|
|
|
|
|
|
|
|
|
|
- id |
|
|
|
- `id` |
|
|
|
- title |
|
|
|
- `title` |
|
|
|
- body |
|
|
|
- `body` |
|
|
|
- date |
|
|
|
- `date` |
|
|
|
|
|
|
|
|
|
|
|
Database class should also have CRUD methods like getAllNotes, deleteAllNotes, addNote, deleteNote, updateNote. |
|
|
|
Database class should also have CRUD methods like `getAllNotes`, `deleteAllNotes`, `addNote`, `deleteNote`, `updateNote`. |
|
|
|
|
|
|
|
|
|
|
|
- getAllNotes() |
|
|
|
- `getAllNotes()` |
|
|
|
- deleteAllNotes() |
|
|
|
- `deleteAllNotes()` |
|
|
|
- addNote(note: Note) |
|
|
|
- `addNote(note: Note)` |
|
|
|
- deleteNote(note: Note) |
|
|
|
- `deleteNote(note: Note)` |
|
|
|
- updateNote(oldNote: Note, newNote: Note) |
|
|
|
- `updateNote(oldNote: Note, newNote: Note)` |
|
|
|
|
|
|
|
|
|
|
|
### Note.dart |
|
|
|
### Note.dart |
|
|
|
|
|
|
|
|
|
|
|
Model class for Note object. |
|
|
|
Model class for Note object. |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
```dart |
|
|
|
class Note { |
|
|
|
class Note { |
|
|
|
int id; |
|
|
|
int id; |
|
|
|
String title; |
|
|
|
String title; |
|
|
@ -80,6 +77,6 @@ class Note { |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### Hints: |
|
|
|
### Notions |
|
|
|
|
|
|
|
|
|
|
|
[https://pub.dev/packages/sqflite](https://pub.dev/packages/sqflite) [https://flutter.dev/docs/development/packages-and-plugins/developing-packages](https://flutter.dev/docs/development/packages-and-plugins/developing-packages) |
|
|
|
[Developing packages with Dart](https://flutter.dev/docs/development/packages-and-plugins/developing-packages) |
|
|
|