Skip to content

Commit

Permalink
finished but addable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayman-Al-Khatib committed Feb 26, 2023
1 parent f891ad5 commit 84e8cf4
Show file tree
Hide file tree
Showing 32 changed files with 1,368 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
Binary file added assets/fonts/Poppins-Regular.ttf
Binary file not shown.
11 changes: 11 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';

const Color kPrimaryColor = Color(0xff62FCD7);
const kNotesBox = 'notes_box';
const List<Color> kcolors = [
Color(0xffAC3931),
Color(0xffE5D352),
Color(0xffD9E76C),
Color(0xff537D8D),
Color(0xff482C3d),
];
25 changes: 25 additions & 0 deletions lib/cubit/add_note_cubit/add_note_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:note_app/constants.dart';
import 'package:note_app/models/note_model.dart';

part 'add_note_state.dart';

class AddNoteCubit extends Cubit<AddNoteState> {
AddNoteCubit() : super(AddNoteInitial());
Color color = const Color(0xffAC3931);
addnote(NoteModel note) async {
emit(AddNoteLoading());
note.color = color.value;
try {
var notebox = Hive.box<NoteModel>(kNotesBox);
await notebox.add(note);
emit(AddNoteSuccess());
} catch (e) {
emit(AddNoteFailure(e.toString()));
}
}
}
15 changes: 15 additions & 0 deletions lib/cubit/add_note_cubit/add_note_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
part of 'add_note_cubit.dart';

@immutable
abstract class AddNoteState {}

class AddNoteInitial extends AddNoteState {}

class AddNoteLoading extends AddNoteState {}

class AddNoteSuccess extends AddNoteState {}

class AddNoteFailure extends AddNoteState {
final String errMessage;
AddNoteFailure(this.errMessage);
}
19 changes: 19 additions & 0 deletions lib/cubit/notes_cubit/notes_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:bloc/bloc.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:meta/meta.dart';

import '../../constants.dart';
import '../../models/note_model.dart';

part 'notes_state.dart';

class NotesCubit extends Cubit<NotesState> {
NotesCubit() : super(NotesInitial());

List<NoteModel>? notes;
FetchAllNodes() {
var notebox = Hive.box<NoteModel>(kNotesBox);
notes = notebox.values.toList();
emit(Notesuccess());
}
}
8 changes: 8 additions & 0 deletions lib/cubit/notes_cubit/notes_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
part of 'notes_cubit.dart';

@immutable
abstract class NotesState {}

class NotesInitial extends NotesState {}

class Notesuccess extends NotesState {}
30 changes: 27 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:note_app/constants.dart';
import 'package:note_app/cubit/add_note_cubit/add_note_cubit.dart';
import 'package:note_app/models/note_model.dart';
import 'package:note_app/simple_bloc_observer.dart';
import 'package:note_app/views/notes_view.dart';

void main(List<String> args) {
import 'cubit/notes_cubit/notes_cubit.dart';

void main(List<String> args) async {
await Hive.initFlutter();
Bloc.observer = SimpleBlocObserver();
Hive.registerAdapter(NoteModelAdapter());
await Hive.openBox<NoteModel>(kNotesBox);
runApp(NotesApp());
}

Expand All @@ -9,8 +22,19 @@ class NotesApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(

return BlocProvider(
create: (context) => NotesCubit(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
brightness: Brightness.dark,
fontFamily: 'Poppins',
textSelectionTheme: TextSelectionThemeData(
selectionHandleColor: Colors.green,
),
),
home: const NotesView(),
),
);
}
}
21 changes: 21 additions & 0 deletions lib/models/note_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:hive_flutter/adapters.dart';
part 'note_model.g.dart';

@HiveType(typeId: 0)
class NoteModel extends HiveObject {
@HiveField(0)
String title;
@HiveField(1)
String content;
@HiveField(2)
final String date;
@HiveField(3)
int color;

NoteModel({
required this.title,
required this.content,
required this.date,
required this.color,
});
}
50 changes: 50 additions & 0 deletions lib/models/note_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions lib/simple_bloc_observer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class SimpleBlocObserver implements BlocObserver {
@override
void onChange(BlocBase bloc, Change change) {
debugPrint('change = ${change}');
}

@override
void onClose(BlocBase bloc) {
debugPrint('Close = ${bloc}');
}

@override
void onCreate(BlocBase bloc) {
debugPrint('Create = ${bloc}');
}

@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
debugPrint('Error = ${bloc}');
}

@override
void onEvent(Bloc bloc, Object? event) {
debugPrint('Event = ${bloc}');
}

@override
void onTransition(Bloc bloc, Transition transition) {
debugPrint('Transition = ${bloc}');
}
}
16 changes: 16 additions & 0 deletions lib/views/edit_note.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:note_app/models/note_model.dart';
import 'package:note_app/views/widgets/edit_note_view_body.dart';

class EditNotesView extends StatelessWidget {
const EditNotesView({super.key, required this.note});
final NoteModel note;
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: EditNotesViewBody(note: note),
),
);
}
}
29 changes: 29 additions & 0 deletions lib/views/notes_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:note_app/cubit/notes_cubit/notes_cubit.dart';
import 'package:note_app/views/widgets/add_note_botton_shett.dart';
import 'package:note_app/views/widgets/note_view_body.dart';

class NotesView extends StatelessWidget {
const NotesView({super.key});

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
context: context,
builder: (context) => const AddButtonSheet());
},
),
body: NotesViewBody(),
));
}
}
41 changes: 41 additions & 0 deletions lib/views/widgets/CustomButton.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ignore_for_file: non_constant_identifier_names

import 'package:flutter/material.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
import 'package:note_app/constants.dart';

class CustomButton extends StatelessWidget {
String Titel;
VoidCallback? onTap;
bool? isLoading = false;
CustomButton({super.key, required this.Titel, this.onTap, this.isLoading});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
decoration: BoxDecoration(color: kPrimaryColor, borderRadius: BorderRadius.circular(8)),
width: double.infinity,
height: 60,
child: Center(
child: isLoading == true
?const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
color: Colors.black,
),
)
: Text(
'$Titel',
style:const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold,
),
)),
),
);
}
}
44 changes: 44 additions & 0 deletions lib/views/widgets/add_note_botton_shett.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
import 'package:note_app/cubit/add_note_cubit/add_note_cubit.dart';
import 'package:note_app/cubit/notes_cubit/notes_cubit.dart';
import 'package:note_app/views/widgets/CustomButton.dart';
import 'package:note_app/views/widgets/custom_text_field.dart';

import 'add_note_form.dart';

class AddButtonSheet extends StatelessWidget {
const AddButtonSheet({super.key});

@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => AddNoteCubit(),
child: BlocConsumer<AddNoteCubit, AddNoteState>(
listener: (context, state) {
if (state is AddNoteFailure) {
debugPrint('error ${state.errMessage}');
}
if (state is AddNoteSuccess) {
Navigator.pop(context);
BlocProvider.of<NotesCubit>(context).FetchAllNodes();
}
},
builder: (context, state) {
return AbsorbPointer(
absorbing: state is AddNoteLoading ? true : false,
child: Padding(
padding: EdgeInsets.only(
left: 16,
right: 16,
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: SingleChildScrollView(child: AddNoteForm()),
),
);
},
),
);
}
}
Loading

0 comments on commit 84e8cf4

Please sign in to comment.