forked from firka/student-legacy
finished notes page
This commit is contained in:
parent
f238b86dc7
commit
5476397af6
53
filcnaplo/lib/api/providers/self_note_provider.dart
Normal file
53
filcnaplo/lib/api/providers/self_note_provider.dart
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||||
|
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||||
|
import 'package:filcnaplo/models/self_note.dart';
|
||||||
|
import 'package:filcnaplo/models/user.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class SelfNoteProvider with ChangeNotifier {
|
||||||
|
late List<SelfNote> _notes;
|
||||||
|
late BuildContext _context;
|
||||||
|
List<SelfNote> get notes => _notes;
|
||||||
|
|
||||||
|
SelfNoteProvider({
|
||||||
|
List<SelfNote> initialNotes = const [],
|
||||||
|
required BuildContext context,
|
||||||
|
}) {
|
||||||
|
_notes = List.castFrom(initialNotes);
|
||||||
|
_context = context;
|
||||||
|
|
||||||
|
if (_notes.isEmpty) restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore self notes from db
|
||||||
|
Future<void> restore() async {
|
||||||
|
String? userId = Provider.of<UserProvider>(_context, listen: false).id;
|
||||||
|
|
||||||
|
// load self notes from db
|
||||||
|
if (userId != null) {
|
||||||
|
var dbNotes = await Provider.of<DatabaseProvider>(_context, listen: false)
|
||||||
|
.userQuery
|
||||||
|
.getSelfNotes(userId: userId);
|
||||||
|
_notes = dbNotes;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetches fresh data from api (not needed, cuz no api for that)
|
||||||
|
// Future<void> fetch() async {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// store self notes in db
|
||||||
|
Future<void> store(List<SelfNote> notes) async {
|
||||||
|
User? user = Provider.of<UserProvider>(_context, listen: false).user;
|
||||||
|
if (user == null) throw "Cannot store Self Notes for User null";
|
||||||
|
String userId = user.id;
|
||||||
|
|
||||||
|
await Provider.of<DatabaseProvider>(_context, listen: false)
|
||||||
|
.userStore
|
||||||
|
.storeSelfNotes(notes, userId: userId);
|
||||||
|
_notes = notes;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import 'package:filcnaplo/api/providers/ad_provider.dart';
|
|||||||
import 'package:filcnaplo/api/providers/live_card_provider.dart';
|
import 'package:filcnaplo/api/providers/live_card_provider.dart';
|
||||||
import 'package:filcnaplo/api/providers/news_provider.dart';
|
import 'package:filcnaplo/api/providers/news_provider.dart';
|
||||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||||
|
import 'package:filcnaplo/api/providers/self_note_provider.dart';
|
||||||
import 'package:filcnaplo/api/providers/status_provider.dart';
|
import 'package:filcnaplo/api/providers/status_provider.dart';
|
||||||
import 'package:filcnaplo/models/config.dart';
|
import 'package:filcnaplo/models/config.dart';
|
||||||
import 'package:filcnaplo/theme/observer.dart';
|
import 'package:filcnaplo/theme/observer.dart';
|
||||||
@ -158,22 +159,25 @@ class App extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider<LiveCardProvider>(
|
ChangeNotifierProvider<LiveCardProvider>(
|
||||||
create: (context) => LiveCardProvider(
|
create: (_) => LiveCardProvider(
|
||||||
timetable: timetable,
|
timetable: timetable,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider<GoalProvider>(
|
ChangeNotifierProvider<GoalProvider>(
|
||||||
create: (context) => GoalProvider(
|
create: (_) => GoalProvider(
|
||||||
database: database,
|
database: database,
|
||||||
user: user,
|
user: user,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider<ShareProvider>(
|
ChangeNotifierProvider<ShareProvider>(
|
||||||
create: (context) => ShareProvider(
|
create: (_) => ShareProvider(
|
||||||
user: user,
|
user: user,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
ChangeNotifierProvider<SelfNoteProvider>(
|
||||||
|
create: (context) => SelfNoteProvider(context: context),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: Consumer<ThemeModeObserver>(
|
child: Consumer<ThemeModeObserver>(
|
||||||
builder: (context, themeMode, child) {
|
builder: (context, themeMode, child) {
|
||||||
|
@ -187,9 +187,9 @@ class UserDatabaseStore {
|
|||||||
where: "id = ?", whereArgs: [userId]);
|
where: "id = ?", whereArgs: [userId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> storeSelfNotes(List<SelfNote> absences,
|
Future<void> storeSelfNotes(List<SelfNote> selfNotes,
|
||||||
{required String userId}) async {
|
{required String userId}) async {
|
||||||
String selfNotesJson = jsonEncode(absences.map((e) => e.json).toList());
|
String selfNotesJson = jsonEncode(selfNotes.map((e) => e.json).toList());
|
||||||
await db.update("user_data", {"self_notes": selfNotesJson},
|
await db.update("user_data", {"self_notes": selfNotesJson},
|
||||||
where: "id = ?", whereArgs: [userId]);
|
where: "id = ?", whereArgs: [userId]);
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,10 @@ class SelfNote {
|
|||||||
json: json,
|
json: json,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get toJson => {
|
||||||
|
'id': id,
|
||||||
|
'title': title,
|
||||||
|
'content': content,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,20 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class Panel extends StatelessWidget {
|
class Panel extends StatelessWidget {
|
||||||
const Panel(
|
const Panel({
|
||||||
{super.key, this.child, this.title, this.padding, this.hasShadow = true});
|
super.key,
|
||||||
|
this.child,
|
||||||
|
this.title,
|
||||||
|
this.padding,
|
||||||
|
this.hasShadow = true,
|
||||||
|
this.isTransparent = false,
|
||||||
|
});
|
||||||
|
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
final Widget? title;
|
final Widget? title;
|
||||||
final EdgeInsetsGeometry? padding;
|
final EdgeInsetsGeometry? padding;
|
||||||
final bool hasShadow;
|
final bool hasShadow;
|
||||||
|
final bool isTransparent;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -26,9 +33,11 @@ class Panel extends StatelessWidget {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(16.0),
|
borderRadius: BorderRadius.circular(16.0),
|
||||||
color: Theme.of(context).colorScheme.background,
|
color: isTransparent
|
||||||
|
? Colors.transparent
|
||||||
|
: Theme.of(context).colorScheme.background,
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
if (hasShadow &&
|
if ((hasShadow && !isTransparent) &&
|
||||||
Provider.of<SettingsProvider>(context, listen: false)
|
Provider.of<SettingsProvider>(context, listen: false)
|
||||||
.shadowEffect)
|
.shadowEffect)
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
|
186
filcnaplo_mobile_ui/lib/screens/notes/add_note_screen.dart
Normal file
186
filcnaplo_mobile_ui/lib/screens/notes/add_note_screen.dart
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
|
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||||
|
import 'package:filcnaplo/api/providers/self_note_provider.dart';
|
||||||
|
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||||
|
import 'package:filcnaplo/models/self_note.dart';
|
||||||
|
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/homework_provider.dart';
|
||||||
|
import 'package:filcnaplo_mobile_ui/screens/notes/notes_screen.i18n.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
class AddNoteScreen extends StatefulWidget {
|
||||||
|
const AddNoteScreen({super.key, this.initialNote});
|
||||||
|
|
||||||
|
final SelfNote? initialNote;
|
||||||
|
|
||||||
|
@override
|
||||||
|
AddNoteScreenState createState() => AddNoteScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddNoteScreenState extends State<AddNoteScreen> {
|
||||||
|
late UserProvider user;
|
||||||
|
late HomeworkProvider homeworkProvider;
|
||||||
|
late DatabaseProvider databaseProvider;
|
||||||
|
late SelfNoteProvider selfNoteProvider;
|
||||||
|
|
||||||
|
final _contentController = TextEditingController();
|
||||||
|
final _titleController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_contentController.text = widget.initialNote?.content ?? '';
|
||||||
|
_titleController.text = widget.initialNote?.title ?? '';
|
||||||
|
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
user = Provider.of<UserProvider>(context);
|
||||||
|
homeworkProvider = Provider.of<HomeworkProvider>(context);
|
||||||
|
databaseProvider = Provider.of<DatabaseProvider>(context);
|
||||||
|
selfNoteProvider = Provider.of<SelfNoteProvider>(context);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
|
leading: BackButton(color: AppColors.of(context).text),
|
||||||
|
title: Text(
|
||||||
|
widget.initialNote == null ? 'new_note'.i18n : 'edit_note'.i18n,
|
||||||
|
style: TextStyle(
|
||||||
|
color: AppColors.of(context).text,
|
||||||
|
fontSize: 26.0,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(10.1),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
// handle tap
|
||||||
|
if (_contentController.text.replaceAll(' ', '') == '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var notes = selfNoteProvider.notes;
|
||||||
|
|
||||||
|
if (widget.initialNote == null) {
|
||||||
|
notes.add(SelfNote.fromJson({
|
||||||
|
'id': const Uuid().v4(),
|
||||||
|
'title': _titleController.text.replaceAll(' ', '') == ''
|
||||||
|
? null
|
||||||
|
: _titleController.text,
|
||||||
|
'content': _contentController.text
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
var i =
|
||||||
|
notes.indexWhere((e) => e.id == widget.initialNote!.id);
|
||||||
|
|
||||||
|
notes[i] = SelfNote.fromJson({
|
||||||
|
'id': notes[i].id,
|
||||||
|
'title': _titleController.text.replaceAll(' ', '') == ''
|
||||||
|
? null
|
||||||
|
: _titleController.text,
|
||||||
|
'content': _contentController.text,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await selfNoteProvider.store(notes);
|
||||||
|
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (widget.initialNote != null) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
IconTheme(
|
||||||
|
data: IconThemeData(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
FeatherIcons.check,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconTheme(
|
||||||
|
data: IconThemeData(
|
||||||
|
color:
|
||||||
|
Theme.of(context).brightness == Brightness.light
|
||||||
|
? Colors.black.withOpacity(.5)
|
||||||
|
: Colors.white.withOpacity(.3),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
FeatherIcons.check,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 22.0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
controller: _titleController,
|
||||||
|
expands: false,
|
||||||
|
maxLines: 1,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
|
hintText: "hint_t".i18n,
|
||||||
|
hintStyle: const TextStyle(
|
||||||
|
fontSize: 22.0,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 22.0,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _contentController,
|
||||||
|
expands: true,
|
||||||
|
minLines: null,
|
||||||
|
maxLines: null,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
|
hintText: "hint".i18n,
|
||||||
|
hintStyle: const TextStyle(fontSize: 16.0),
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
style: const TextStyle(fontSize: 16.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
153
filcnaplo_mobile_ui/lib/screens/notes/note_view_screen.dart
Normal file
153
filcnaplo_mobile_ui/lib/screens/notes/note_view_screen.dart
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
import 'package:filcnaplo/api/providers/self_note_provider.dart';
|
||||||
|
import 'package:filcnaplo/models/self_note.dart';
|
||||||
|
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||||
|
import 'package:filcnaplo_mobile_ui/screens/notes/add_note_screen.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class NoteViewScreen extends StatefulWidget {
|
||||||
|
const NoteViewScreen({super.key, required this.note});
|
||||||
|
|
||||||
|
final SelfNote note;
|
||||||
|
|
||||||
|
@override
|
||||||
|
NoteViewScreenState createState() => NoteViewScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class NoteViewScreenState extends State<NoteViewScreen> {
|
||||||
|
late SelfNoteProvider selfNoteProvider;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
selfNoteProvider = Provider.of<SelfNoteProvider>(context);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
|
leading: BackButton(color: AppColors.of(context).text),
|
||||||
|
title: Text(
|
||||||
|
widget.note.title ?? '${widget.note.content.split(' ')[0]}...',
|
||||||
|
style: TextStyle(
|
||||||
|
color: AppColors.of(context).text,
|
||||||
|
fontSize: 26.0,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(10.1),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
// handle tap
|
||||||
|
Navigator.of(context, rootNavigator: true).push(
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
AddNoteScreen(initialNote: widget.note)));
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
IconTheme(
|
||||||
|
data: IconThemeData(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
FeatherIcons.edit,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconTheme(
|
||||||
|
data: IconThemeData(
|
||||||
|
color:
|
||||||
|
Theme.of(context).brightness == Brightness.light
|
||||||
|
? Colors.black.withOpacity(.5)
|
||||||
|
: Colors.white.withOpacity(.3),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
FeatherIcons.edit,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(10.1),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
// handle tap
|
||||||
|
var notes = selfNoteProvider.notes;
|
||||||
|
notes.removeWhere((e) => e.id == widget.note.id);
|
||||||
|
await selfNoteProvider.store(notes);
|
||||||
|
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
IconTheme(
|
||||||
|
data: IconThemeData(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
FeatherIcons.trash2,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconTheme(
|
||||||
|
data: IconThemeData(
|
||||||
|
color:
|
||||||
|
Theme.of(context).brightness == Brightness.light
|
||||||
|
? Colors.black.withOpacity(.5)
|
||||||
|
: Colors.white.withOpacity(.3),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
FeatherIcons.trash2,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
widget.note.content,
|
||||||
|
textAlign: TextAlign.justify,
|
||||||
|
style: const TextStyle(fontSize: 18.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||||
|
import 'package:filcnaplo/api/providers/self_note_provider.dart';
|
||||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||||
import 'package:filcnaplo/theme/colors/colors.dart';
|
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||||
import 'package:filcnaplo/utils/format.dart';
|
import 'package:filcnaplo/utils/format.dart';
|
||||||
@ -8,10 +9,15 @@ import 'package:filcnaplo_kreta_api/models/homework.dart';
|
|||||||
import 'package:filcnaplo_kreta_api/providers/homework_provider.dart';
|
import 'package:filcnaplo_kreta_api/providers/homework_provider.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/common/empty.dart';
|
import 'package:filcnaplo_mobile_ui/common/empty.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/common/panel/panel.dart';
|
import 'package:filcnaplo_mobile_ui/common/panel/panel.dart';
|
||||||
|
import 'package:filcnaplo_mobile_ui/common/soon_alert/soon_alert.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/common/widgets/tick_tile.dart';
|
import 'package:filcnaplo_mobile_ui/common/widgets/tick_tile.dart';
|
||||||
|
import 'package:filcnaplo_mobile_ui/screens/notes/add_note_screen.dart';
|
||||||
|
import 'package:filcnaplo_mobile_ui/screens/notes/note_view_screen.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/screens/notes/notes_screen.i18n.dart';
|
import 'package:filcnaplo_mobile_ui/screens/notes/notes_screen.i18n.dart';
|
||||||
|
import 'package:filcnaplo_mobile_ui/screens/notes/self_note_tile.dart';
|
||||||
import 'package:filcnaplo_premium/providers/premium_provider.dart';
|
import 'package:filcnaplo_premium/providers/premium_provider.dart';
|
||||||
import 'package:filcnaplo_premium/ui/mobile/premium/premium_inline.dart';
|
import 'package:filcnaplo_premium/ui/mobile/premium/premium_inline.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -29,6 +35,7 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
late UserProvider user;
|
late UserProvider user;
|
||||||
late HomeworkProvider homeworkProvider;
|
late HomeworkProvider homeworkProvider;
|
||||||
late DatabaseProvider databaseProvider;
|
late DatabaseProvider databaseProvider;
|
||||||
|
late SelfNoteProvider selfNoteProvider;
|
||||||
|
|
||||||
List<Widget> noteTiles = [];
|
List<Widget> noteTiles = [];
|
||||||
|
|
||||||
@ -37,6 +44,7 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
user = Provider.of<UserProvider>(context);
|
user = Provider.of<UserProvider>(context);
|
||||||
homeworkProvider = Provider.of<HomeworkProvider>(context);
|
homeworkProvider = Provider.of<HomeworkProvider>(context);
|
||||||
databaseProvider = Provider.of<DatabaseProvider>(context);
|
databaseProvider = Provider.of<DatabaseProvider>(context);
|
||||||
|
selfNoteProvider = Provider.of<SelfNoteProvider>(context);
|
||||||
|
|
||||||
void generateTiles() {
|
void generateTiles() {
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
@ -47,6 +55,7 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
// DateTime.now().month, DateTime.now().day + 3)))
|
// DateTime.now().month, DateTime.now().day + 3)))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
// todo tiles
|
||||||
List<Widget> toDoTiles = [];
|
List<Widget> toDoTiles = [];
|
||||||
|
|
||||||
if (hw.isNotEmpty) {
|
if (hw.isNotEmpty) {
|
||||||
@ -77,8 +86,42 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tiles.isNotEmpty) {
|
// self notes
|
||||||
} else {
|
List<Widget> selfNoteTiles = [];
|
||||||
|
|
||||||
|
if (selfNoteProvider.notes.isNotEmpty) {
|
||||||
|
selfNoteTiles.addAll(selfNoteProvider.notes.map(
|
||||||
|
(e) => SelfNoteTile(
|
||||||
|
title: e.title ?? e.content.split(' ')[0],
|
||||||
|
content: e.content,
|
||||||
|
onTap: () => Navigator.of(context, rootNavigator: true).push(
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (context) => NoteViewScreen(note: e))),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selfNoteTiles.isNotEmpty) {
|
||||||
|
// padding
|
||||||
|
tiles.add(const SizedBox(
|
||||||
|
height: 28.0,
|
||||||
|
));
|
||||||
|
|
||||||
|
// actual thing
|
||||||
|
tiles.add(Panel(
|
||||||
|
title: Text('your_notes'.i18n),
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
isTransparent: true,
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 18.0,
|
||||||
|
runSpacing: 18.0,
|
||||||
|
children: selfNoteTiles,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert empty tile
|
||||||
|
if (tiles.isEmpty) {
|
||||||
tiles.insert(
|
tiles.insert(
|
||||||
0,
|
0,
|
||||||
Padding(
|
Padding(
|
||||||
@ -123,6 +166,7 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// handle tap
|
// handle tap
|
||||||
|
SoonAlert.show(context: context);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
||||||
@ -165,6 +209,9 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// handle tap
|
// handle tap
|
||||||
|
Navigator.of(context, rootNavigator: true).push(
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (context) => const AddNoteScreen()));
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
color: Theme.of(context).colorScheme.primary.withOpacity(0.4),
|
||||||
@ -206,8 +253,12 @@ class NotesScreenState extends State<NotesScreen> {
|
|||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () {
|
||||||
await homeworkProvider.fetch();
|
Provider.of<HomeworkProvider>(context, listen: false)
|
||||||
|
.fetch(from: DateTime.now().subtract(const Duration(days: 30)));
|
||||||
|
Provider.of<SelfNoteProvider>(context, listen: false).restore();
|
||||||
|
|
||||||
|
return Future(() => null);
|
||||||
},
|
},
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
@ -8,18 +8,33 @@ extension SettingsLocalization on String {
|
|||||||
"empty": "You don't have any notes",
|
"empty": "You don't have any notes",
|
||||||
"todo": "Tasks",
|
"todo": "Tasks",
|
||||||
"homework": "Homework",
|
"homework": "Homework",
|
||||||
|
"new_note": "New Note",
|
||||||
|
"edit_note": "Edit Note",
|
||||||
|
"hint": "Note content...",
|
||||||
|
"hint_t": "Note title...",
|
||||||
|
"your_notes": "Your Notes",
|
||||||
},
|
},
|
||||||
"hu_hu": {
|
"hu_hu": {
|
||||||
"notes": "Füzet",
|
"notes": "Füzet",
|
||||||
"empty": "Nincsenek jegyzeteid",
|
"empty": "Nincsenek jegyzeteid",
|
||||||
"todo": "Feladatok",
|
"todo": "Feladatok",
|
||||||
"homework": "Házi feladat",
|
"homework": "Házi feladat",
|
||||||
|
"new_note": "Új jegyzet",
|
||||||
|
"edit_note": "Jegyzet szerkesztése",
|
||||||
|
"hint": "Jegyzet tartalma...",
|
||||||
|
"hint_t": "Jegyzet címe...",
|
||||||
|
"your_notes": "Jegyzeteid",
|
||||||
},
|
},
|
||||||
"de_de": {
|
"de_de": {
|
||||||
"notes": "Broschüre",
|
"notes": "Broschüre",
|
||||||
"empty": "Sie haben keine Notizen",
|
"empty": "Sie haben keine Notizen",
|
||||||
"todo": "Aufgaben",
|
"todo": "Aufgaben",
|
||||||
"homework": "Hausaufgaben",
|
"homework": "Hausaufgaben",
|
||||||
|
"new_note": "Neue Notiz",
|
||||||
|
"edit_note": "Notiz bearbeiten",
|
||||||
|
"hint": "Inhalt beachten...",
|
||||||
|
"hint_t": "Titel notieren...",
|
||||||
|
"your_notes": "Deine Noten",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
64
filcnaplo_mobile_ui/lib/screens/notes/self_note_tile.dart
Normal file
64
filcnaplo_mobile_ui/lib/screens/notes/self_note_tile.dart
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import 'package:filcnaplo/models/settings.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class SelfNoteTile extends StatelessWidget {
|
||||||
|
const SelfNoteTile(
|
||||||
|
{super.key, required this.title, required this.content, this.onTap});
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final String content;
|
||||||
|
final Function()? onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 172.0,
|
||||||
|
width: 172.0,
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(16.0),
|
||||||
|
color: Theme.of(context).colorScheme.background,
|
||||||
|
boxShadow: [
|
||||||
|
if (Provider.of<SettingsProvider>(context, listen: false)
|
||||||
|
.shadowEffect)
|
||||||
|
BoxShadow(
|
||||||
|
offset: const Offset(0, 21),
|
||||||
|
blurRadius: 23.0,
|
||||||
|
color: Theme.of(context).shadowColor,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
content.replaceAll('\n', ' '),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
maxLines: 6,
|
||||||
|
style: const TextStyle(fontSize: 17.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 5.0,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 152.0,
|
||||||
|
child: Text(
|
||||||
|
title,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 14.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -240,10 +240,13 @@ class SettingsScreenState extends State<SettingsScreen>
|
|||||||
// ),
|
// ),
|
||||||
IconButton(
|
IconButton(
|
||||||
splashRadius: 32.0,
|
splashRadius: 32.0,
|
||||||
|
// onPressed: () async => await databaseProvider.userStore
|
||||||
|
// .storeSelfNotes([], userId: user.id!),
|
||||||
onPressed: () async => _openNotes(
|
onPressed: () async => _openNotes(
|
||||||
context,
|
context,
|
||||||
await databaseProvider.userQuery
|
await databaseProvider.userQuery
|
||||||
.toDoItems(userId: user.id!)),
|
.toDoItems(userId: user.id!),
|
||||||
|
),
|
||||||
// _showBottomSheet(user.getUser(user.id ?? "")),
|
// _showBottomSheet(user.getUser(user.id ?? "")),
|
||||||
icon: Icon(FeatherIcons.fileText,
|
icon: Icon(FeatherIcons.fileText,
|
||||||
color: AppColors.of(context).text.withOpacity(0.8)),
|
color: AppColors.of(context).text.withOpacity(0.8)),
|
||||||
|
@ -59,6 +59,7 @@ dependencies:
|
|||||||
image_crop:
|
image_crop:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/kimaah/image_crop.git
|
url: https://github.com/kimaah/image_crop.git
|
||||||
|
uuid: ^4.2.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_lints: ^3.0.1
|
flutter_lints: ^3.0.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user