Skip to content

Commit

Permalink
added the minor features for users to be using
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-which-qp committed Jun 9, 2024
1 parent c972435 commit cffacaf
Show file tree
Hide file tree
Showing 8 changed files with 699 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:note_app/app/helpers/hive_manager.dart';
import 'package:note_app/app/resources/home/views/cloud_notes/models/cloud_note_model.dart';
import 'package:note_app/app/resources/home/views/cloud_notes/views/cloud_read_note.dart';
import 'package:note_app/app/router/route_name.dart';
import 'package:note_app/m_functions/navigate_to.dart';
import 'package:note_app/providers/change_view_style_provider.dart';
import 'package:note_app/providers/theme_provider.dart';
import 'package:note_app/request/get_request.dart';
Expand Down Expand Up @@ -45,6 +50,7 @@ class _CloudNotesScreenState extends State<CloudNotesScreen> {
await cloudNoteModel.clear();
await cloudNoteModel.addAll(cloudNotes);

setState(() {});
logger.i('Notes stored successfully');
}
} catch (error) {
Expand Down Expand Up @@ -79,7 +85,10 @@ class _CloudNotesScreenState extends State<CloudNotesScreen> {

try {
if (status == 200) {
showSuccess(msg);
Fluttertoast.showToast(
msg: '$msg',
toastLength: Toast.LENGTH_SHORT,
);

if (mounted) {
fetchNotes();
Expand Down Expand Up @@ -181,7 +190,10 @@ class _CloudNotesScreenState extends State<CloudNotesScreen> {
actions: [
if (Platform.isIOS)
IconButton(
onPressed: () {},
onPressed: () {
context.pop();
context.pushNamed(RouteName.cloud_create_notes_screen);
},
icon: const Icon(
CupertinoIcons.add_circled,
),
Expand All @@ -191,7 +203,10 @@ class _CloudNotesScreenState extends State<CloudNotesScreen> {
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: Platform.isAndroid
? FloatingActionButton(
onPressed: () {},
onPressed: () {
context.pop();
context.pushNamed(RouteName.cloud_create_notes_screen);
},
backgroundColor:
checkTheme.mTheme == true ? cardColor : backColor,
tooltip: 'Add Note',
Expand Down Expand Up @@ -226,10 +241,11 @@ class _CloudNotesScreenState extends State<CloudNotesScreen> {
final CloudNoteModel? note = notes.get(key);
return GestureDetector(
onTap: () {
// navigateTo(context, destination: ReadNotesScreen(
// note: note,
// noteKey: key,
// ));
navigateTo(context,
destination: CloudReadNote(
note: note,
noteKey: key,
));
},
onLongPress: () {
deleteDialog(key, note);
Expand Down
210 changes: 210 additions & 0 deletions lib/app/resources/home/views/cloud_notes/views/cloud_create_note.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:note_app/app/helpers/hive_manager.dart';
import 'package:note_app/app/router/route_name.dart';
import 'package:note_app/m_functions/navigate_to.dart';
import 'package:note_app/providers/theme_provider.dart';
import 'package:note_app/request/post_request.dart';
import 'package:note_app/utils/const_values.dart';
import 'package:note_app/utils/message_dialog.dart';
import 'package:provider/provider.dart';

class CloudCreateNote extends StatefulWidget {
const CloudCreateNote({super.key});

@override
State<CloudCreateNote> createState() => _CloudCreateNoteState();
}

class _CloudCreateNoteState extends State<CloudCreateNote> {
final TextEditingController _noteTitle = TextEditingController();
final TextEditingController _noteText = TextEditingController();
final scaffoldKey = GlobalKey<ScaffoldState>();

TextStyle? myTextStyle;
TextAlign? myTextAlign;

bool? _isNotEmpty;

final goToNotes = FocusNode();

Future createNote(String? title, String? notes) async {

final userModel = HiveManager().userModelBox;
final storeData = HiveManager().noteModelBox;

var params = {
'note_title': '$title',
'note_content': '$notes',
};

var res = await PostRequest.makePostRequest(
requestEnd: 'user/create_notes',
params: params,
context: context,
bearer: userModel.get(tokenKey)!.accessToken,
);

logger.i(res);
}

Future<bool> checkIfNoteIsNotEmptyWhenGoingBack() async {
final storeData = HiveManager().cloudNoteModelBox;
if (_noteText.text.isNotEmpty || _noteTitle.text.isNotEmpty) {
final String noteTitle = _noteTitle.text;
final String note = _noteText.text;

createNote(noteTitle, note);

await Fluttertoast.showToast(
msg: 'Note Saved',
toastLength: Toast.LENGTH_SHORT,
);
if(mounted) {
context.pop();
context.pushNamed(RouteName.cloud_notes);
}
_isNotEmpty = true;
} else {
await Fluttertoast.showToast(
msg: 'Note was empty, nothing was saved',
toastLength: Toast.LENGTH_SHORT,
);
if(mounted) {
context.pop();
context.pushNamed(RouteName.cloud_notes);
}
_isNotEmpty = false;
}
return _isNotEmpty!;
}

void checkIfNoteIsNotEmptyAndSaveNote() {
final storeData = HiveManager().cloudNoteModelBox;
if (_noteTitle.text.isEmpty || _noteText.text.isEmpty) {
Fluttertoast.showToast(
msg: 'Title or note body cannot be empty',
toastLength: Toast.LENGTH_SHORT,
);
return;
} else {
final String noteTitle = _noteTitle.text;
final String note = _noteText.text;

createNote(noteTitle, note);

Fluttertoast.showToast(
msg: 'Note Saved',
toastLength: Toast.LENGTH_SHORT,
);
context.pop();
context.pushNamed(RouteName.cloud_notes);
}
}

@override
void initState() {
super.initState();
myTextStyle = const TextStyle(
fontSize: 18.5,
);
myTextAlign = TextAlign.left;
}

@override
void dispose() {
super.dispose();
_noteTitle.dispose();
_noteText.dispose();
}

@override
Widget build(BuildContext context) {
final checkTheme = Provider.of<ThemeProvider>(context);
var height = MediaQuery.of(context).size.height;
return WillPopScope(
onWillPop: checkIfNoteIsNotEmptyWhenGoingBack,
child: Scaffold(
key: scaffoldKey,
appBar: AppBar(
// used a text form field for the app bar
leading: Platform.isIOS
? IconButton(
icon: const Icon(CupertinoIcons.back),
onPressed: checkIfNoteIsNotEmptyWhenGoingBack,
)
: null,
title: TextFormField(
autofocus: true,
controller: _noteTitle,
decoration: const InputDecoration(
hintText: 'Create Note Title...',
hintStyle: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
border: InputBorder.none,
),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
onFieldSubmitted: (_) {
FocusScope.of(context).requestFocus(goToNotes);
},
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.sentences,
textInputAction: TextInputAction.next,
),
// ends here //
centerTitle: false,
actions: <Widget>[
TextButton.icon(
onPressed: () {
checkIfNoteIsNotEmptyAndSaveNote();
},
icon: Icon(
Icons.done,
color:
checkTheme.mTheme == false ? Colors.black45 : Colors.white38,
),
label: Text(
'Save',
style: TextStyle(
color: checkTheme.mTheme == false
? Colors.black45
: Colors.white38,
),
),
),
],
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: TextField(
controller: _noteText,
decoration: const InputDecoration(
hintText: 'Type Note...',
hintStyle: TextStyle(),
border: InputBorder.none,
),
textCapitalization: TextCapitalization.sentences,
focusNode: goToNotes,
style: myTextStyle,
textAlign: myTextAlign!,
maxLines: height.toInt(),
),

//TODO! trying to add styling functionality, having issues
//TODO! persisting the style for a saved note
),
),
),
);
}
}
Loading

0 comments on commit cffacaf

Please sign in to comment.