did everything, like really
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// ignore_for_file: no_leading_underscores_for_local_identifiers, use_build_context_synchronously
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -7,6 +8,8 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:refilc/api/providers/database_provider.dart';
|
||||
import 'package:refilc/api/providers/self_note_provider.dart';
|
||||
import 'package:refilc/api/providers/update_provider.dart';
|
||||
import 'package:refilc/models/self_note.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc/utils/format.dart';
|
||||
import 'package:refilc_kreta_api/models/absence.dart';
|
||||
import 'package:refilc_kreta_api/models/homework.dart';
|
||||
@@ -14,6 +17,8 @@ import 'package:refilc_kreta_api/models/subject.dart';
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/providers/homework_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu.dart';
|
||||
import 'package:refilc_mobile_ui/common/bottom_sheet_menu/rounded_bottom_sheet.dart';
|
||||
import 'package:refilc_mobile_ui/common/empty.dart';
|
||||
import 'package:refilc_mobile_ui/common/panel/panel.dart';
|
||||
import 'package:refilc_mobile_ui/common/profile_image/profile_button.dart';
|
||||
@@ -23,6 +28,7 @@ import 'package:refilc_mobile_ui/common/widgets/tick_tile.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc_mobile_ui/pages/notes/submenu/add_note_screen.dart';
|
||||
import 'package:refilc_mobile_ui/pages/notes/submenu/create_image_note.dart';
|
||||
import 'package:refilc_mobile_ui/pages/notes/submenu/note_view_screen.dart';
|
||||
import 'package:refilc_mobile_ui/pages/notes/submenu/self_note_tile.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
@@ -114,13 +120,37 @@ class NotesPageState extends State<NotesPage> with TickerProviderStateMixin {
|
||||
|
||||
if (selfNoteProvider.notes.isNotEmpty) {
|
||||
selfNoteTiles.addAll(selfNoteProvider.notes.reversed.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))),
|
||||
),
|
||||
(e) => e.noteType == NoteType.text
|
||||
? SelfNoteTile(
|
||||
title: e.title ?? e.content.split(' ')[0],
|
||||
content: e.content,
|
||||
onTap: () => Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => NoteViewScreen(note: e))),
|
||||
)
|
||||
: Container(
|
||||
height: MediaQuery.of(context).size.width / 2.42,
|
||||
width: MediaQuery.of(context).size.width / 2.42,
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
if (Provider.of<SettingsProvider>(context, listen: false)
|
||||
.shadowEffect)
|
||||
BoxShadow(
|
||||
offset: const Offset(0, 21),
|
||||
blurRadius: 23.0,
|
||||
color: Theme.of(context).shadowColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
child: Image.memory(
|
||||
const Base64Decoder().convert(e.content),
|
||||
fit: BoxFit.cover,
|
||||
gaplessPlayback: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -235,9 +265,7 @@ class NotesPageState extends State<NotesPage> with TickerProviderStateMixin {
|
||||
feature: PremiumFeature.selfNotes);
|
||||
}
|
||||
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const AddNoteScreen()));
|
||||
showCreationModal(context);
|
||||
},
|
||||
child: Icon(
|
||||
FeatherIcons.plus,
|
||||
@@ -312,4 +340,77 @@ class NotesPageState extends State<NotesPage> with TickerProviderStateMixin {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showCreationModal(BuildContext context) {
|
||||
// _sheetController = _scaffoldKey.currentState?.showBottomSheet(
|
||||
// (context) => RoundedBottomSheet(
|
||||
// borderRadius: 14.0,
|
||||
// child: BottomSheetMenu(items: [
|
||||
// SwitchListTile(
|
||||
// title: Text('show_lesson_num'.i18n),
|
||||
// value:
|
||||
// Provider.of<SettingsProvider>(context).qTimetableLessonNum,
|
||||
// onChanged: (v) {
|
||||
// Provider.of<SettingsProvider>(context, listen: false)
|
||||
// .update(qTimetableLessonNum: v);
|
||||
// })
|
||||
// ])),
|
||||
// backgroundColor: const Color(0x00000000),
|
||||
// elevation: 12.0,
|
||||
// );
|
||||
|
||||
// _sheetController!.closed.then((value) {
|
||||
// // Show fab and grades
|
||||
// if (mounted) {}
|
||||
// });
|
||||
showRoundedModalBottomSheet(
|
||||
context,
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: BottomSheetMenu(items: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
color: Theme.of(context).colorScheme.background),
|
||||
child: ListTile(
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.sticky_note_2_outlined),
|
||||
const SizedBox(
|
||||
width: 10.0,
|
||||
),
|
||||
Text('new_note'.i18n),
|
||||
],
|
||||
),
|
||||
onTap: () => Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const AddNoteScreen())),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10.0,
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
color: Theme.of(context).colorScheme.background),
|
||||
child: ListTile(
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.photo_library_outlined),
|
||||
const SizedBox(
|
||||
width: 10.0,
|
||||
),
|
||||
Text('new_image'.i18n),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ImageNoteEditor(user.user!));
|
||||
},
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ extension ScreensLocalization on String {
|
||||
"hint": "Note content...",
|
||||
"hint_t": "Note title...",
|
||||
"your_notes": "Your Notes",
|
||||
"new_image": "New Image",
|
||||
},
|
||||
"hu_hu": {
|
||||
"notes": "Füzet",
|
||||
@@ -24,6 +25,7 @@ extension ScreensLocalization on String {
|
||||
"hint": "Jegyzet tartalma...",
|
||||
"hint_t": "Jegyzet címe...",
|
||||
"your_notes": "Jegyzeteid",
|
||||
"new_image": "Új kép",
|
||||
},
|
||||
"de_de": {
|
||||
"notes": "Broschüre",
|
||||
@@ -35,6 +37,7 @@ extension ScreensLocalization on String {
|
||||
"hint": "Inhalt beachten...",
|
||||
"hint_t": "Titel notieren...",
|
||||
"your_notes": "Deine Noten",
|
||||
"new_image": "Neues Bild",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -153,7 +153,8 @@ class AddNoteScreenState extends State<AddNoteScreen> {
|
||||
'title': _titleController.text.replaceAll(' ', '') == ''
|
||||
? null
|
||||
: _titleController.text,
|
||||
'content': _contentController.text
|
||||
'content': _contentController.text,
|
||||
'note_type': 'text',
|
||||
}));
|
||||
} else {
|
||||
var i =
|
||||
@@ -165,6 +166,7 @@ class AddNoteScreenState extends State<AddNoteScreen> {
|
||||
? null
|
||||
: _titleController.text,
|
||||
'content': _contentController.text,
|
||||
'note_type': 'text',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
214
refilc_mobile_ui/lib/pages/notes/submenu/create_image_note.dart
Normal file
214
refilc_mobile_ui/lib/pages/notes/submenu/create_image_note.dart
Normal file
@@ -0,0 +1,214 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_crop/image_crop.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc/api/providers/database_provider.dart';
|
||||
import 'package:refilc/api/providers/self_note_provider.dart';
|
||||
import 'package:refilc/models/self_note.dart';
|
||||
import 'package:refilc/models/user.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'notes_screen.i18n.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class ImageNoteEditor extends StatefulWidget {
|
||||
late User u;
|
||||
|
||||
ImageNoteEditor(this.u, {super.key});
|
||||
|
||||
@override
|
||||
State<ImageNoteEditor> createState() => _ImageNoteEditorState();
|
||||
}
|
||||
|
||||
class _ImageNoteEditorState extends State<ImageNoteEditor> {
|
||||
final cropKey = GlobalKey<CropState>();
|
||||
File? _file;
|
||||
File? _sample;
|
||||
File? _lastCropped;
|
||||
|
||||
File? image;
|
||||
Future pickImage() async {
|
||||
try {
|
||||
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
|
||||
if (image == null) return;
|
||||
File imageFile = File(image.path);
|
||||
|
||||
final sample = await ImageCrop.sampleImage(
|
||||
file: imageFile,
|
||||
preferredSize: context.size!.longestSide.ceil(),
|
||||
);
|
||||
|
||||
_sample?.delete();
|
||||
_file?.delete();
|
||||
|
||||
setState(() {
|
||||
_sample = sample;
|
||||
_file = imageFile;
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
log('Failed to pick image: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Widget cropImageWidget() {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: Crop.file(
|
||||
_sample!,
|
||||
key: cropKey,
|
||||
aspectRatio: 1.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget openImageWidget() {
|
||||
return InkWell(
|
||||
customBorder: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14.0),
|
||||
),
|
||||
onTap: () => pickImage(),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(14.0),
|
||||
),
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 32.0, horizontal: 8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"click_here".i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 22.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"select_image".i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _cropImage() async {
|
||||
final scale = cropKey.currentState!.scale;
|
||||
final area = cropKey.currentState!.area;
|
||||
if (area == null || _file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final sample = await ImageCrop.sampleImage(
|
||||
file: _file!,
|
||||
preferredSize: (2000 / scale).round(),
|
||||
);
|
||||
|
||||
final file = await ImageCrop.cropImage(
|
||||
file: sample,
|
||||
area: area,
|
||||
);
|
||||
|
||||
sample.delete();
|
||||
|
||||
_lastCropped?.delete();
|
||||
_lastCropped = file;
|
||||
|
||||
List<int> imageBytes = await _lastCropped!.readAsBytes();
|
||||
String base64Image = base64Encode(imageBytes);
|
||||
|
||||
List<SelfNote> selfNotes =
|
||||
await Provider.of<DatabaseProvider>(context, listen: false)
|
||||
.userQuery
|
||||
.getSelfNotes(userId: widget.u.id);
|
||||
|
||||
selfNotes.add(SelfNote.fromJson({
|
||||
'id': const Uuid().v4(),
|
||||
'content': base64Image,
|
||||
'note_type': 'image'
|
||||
}));
|
||||
|
||||
await Provider.of<DatabaseProvider>(context, listen: false)
|
||||
.userStore
|
||||
.storeSelfNotes(selfNotes, userId: widget.u.id);
|
||||
|
||||
Provider.of<SelfNoteProvider>(context, listen: false).restore();
|
||||
|
||||
debugPrint('$file');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_file?.delete();
|
||||
_sample?.delete();
|
||||
_lastCropped?.delete();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(14.0))),
|
||||
contentPadding: const EdgeInsets.only(top: 10.0),
|
||||
title: Text("new_image".i18n),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0),
|
||||
child: _sample == null ? openImageWidget() : cropImageWidget(),
|
||||
),
|
||||
// if (widget.u.picture != "")
|
||||
// TextButton(
|
||||
// child: Text(
|
||||
// "remove_profile_picture".i18n,
|
||||
// style: const TextStyle(
|
||||
// fontWeight: FontWeight.w500, color: Colors.red),
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// widget.u.picture = "";
|
||||
// Provider.of<DatabaseProvider>(context, listen: false)
|
||||
// .store
|
||||
// .storeUser(widget.u);
|
||||
// Provider.of<UserProvider>(context, listen: false).refresh();
|
||||
// Navigator.of(context).pop(true);
|
||||
// },
|
||||
// ),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
"cancel".i18n,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).maybePop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
"next".i18n,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () async {
|
||||
await _cropImage();
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,11 @@ extension SettingsLocalization on String {
|
||||
"hint": "Note content...",
|
||||
"hint_t": "Note title...",
|
||||
"your_notes": "Your Notes",
|
||||
"next": "Next",
|
||||
"cancel": "Cancel",
|
||||
"click_here": "Click here",
|
||||
"select_image": "to select an image",
|
||||
"new_image": "New Image",
|
||||
},
|
||||
"hu_hu": {
|
||||
"notes": "Füzet",
|
||||
@@ -24,6 +29,11 @@ extension SettingsLocalization on String {
|
||||
"hint": "Jegyzet tartalma...",
|
||||
"hint_t": "Jegyzet címe...",
|
||||
"your_notes": "Jegyzeteid",
|
||||
"next": "Tovább",
|
||||
"cancel": "Mégse",
|
||||
"click_here": "Kattints ide",
|
||||
"select_image": "kép kiválasztásához",
|
||||
"new_image": "Új kép",
|
||||
},
|
||||
"de_de": {
|
||||
"notes": "Broschüre",
|
||||
@@ -35,6 +45,11 @@ extension SettingsLocalization on String {
|
||||
"hint": "Inhalt beachten...",
|
||||
"hint_t": "Titel notieren...",
|
||||
"your_notes": "Deine Noten",
|
||||
"next": "Weiter",
|
||||
"cancel": "Abbrechen",
|
||||
"click_here": "Klicken Sie hier",
|
||||
"select_image": "um ein Bild auszuwählen",
|
||||
"new_image": "Neues Bild",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user