Skip to content

Commit

Permalink
(+) Catatan Screen
Browse files Browse the repository at this point in the history
(+) Add Catatan
(+) Like/Unlike Catatan
  • Loading branch information
rizalord committed Sep 24, 2020
1 parent bd287e7 commit 1195ea8
Show file tree
Hide file tree
Showing 28 changed files with 2,402 additions and 75 deletions.
7 changes: 6 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
package="com.rizalord.unord.unord">
<application
android:label="Unord"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down Expand Up @@ -32,6 +33,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
Binary file added assets/images/catatan_illustration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/default_user_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/sidebar_bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions lib/app/app_module.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:unord/blocs/auth_bloc.dart';
import 'package:unord/blocs/education_bloc.dart';
import 'package:unord/blocs/liked_notes_bloc.dart';
import 'package:unord/blocs/search_catatan_bloc.dart';
import 'package:unord/blocs/subject_bloc.dart';
import 'package:unord/blocs/tab_bloc.dart';
import 'package:unord/blocs/user_bloc.dart';
import 'package:unord/screens/auth/login_screen.dart';
import 'package:unord/screens/auth/register_screen.dart';
import 'package:unord/screens/auth/splash_screen.dart';
import 'package:unord/screens/profile/profile_edit_screen.dart';
import 'package:unord/screens/profile/profile_screen.dart';
import 'package:unord/screens/tab/main_tab.dart';
import 'package:unord/screens/upload/add_note_screen.dart';

import 'app_widget.dart';

Expand All @@ -15,6 +23,11 @@ class AppModule extends MainModule {
List<Bind> get binds => [
Bind((_) => AuthBloc()),
Bind((_) => UserBloc()),
Bind((_) => TabBloc()),
Bind((_) => SearchCatatanBloc()),
Bind((_) => LikedNotesBloc()),
Bind((_) => EducationBloc()),
Bind((_) => SubjectBloc()),
];

@override
Expand All @@ -23,6 +36,9 @@ class AppModule extends MainModule {
ModularRouter('/login', child: (_, __) => LoginScreen()),
ModularRouter('/register', child: (_, __) => RegisterScreen()),
ModularRouter('/general', child: (_, __) => MainTab()),
ModularRouter('/profile', child: (_, __) => ProfileScreen()),
ModularRouter('/profile/edit', child: (_, __) => EditProfileScreen()),
ModularRouter('/note/upload', child: (_, __) => AddNoteScreen()),
];

@override
Expand Down
14 changes: 14 additions & 0 deletions lib/app/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:unord/blocs/auth_bloc.dart';
import 'package:unord/blocs/education_bloc.dart';
import 'package:unord/blocs/liked_notes_bloc.dart';
import 'package:unord/blocs/search_catatan_bloc.dart';
import 'package:unord/blocs/subject_bloc.dart';
import 'package:unord/blocs/tab_bloc.dart';
import 'package:unord/blocs/user_bloc.dart';
import 'package:unord/theme/styles.dart';

Expand All @@ -13,6 +18,15 @@ class AppWidget extends StatelessWidget {
providers: [
BlocProvider<AuthBloc>(create: (context) => Modular.get<AuthBloc>()),
BlocProvider<UserBloc>(create: (context) => Modular.get<UserBloc>()),
BlocProvider<TabBloc>(create: (context) => Modular.get<TabBloc>()),
BlocProvider<SearchCatatanBloc>(
create: (context) => Modular.get<SearchCatatanBloc>()),
BlocProvider<LikedNotesBloc>(
create: (context) => Modular.get<LikedNotesBloc>()),
BlocProvider<EducationBloc>(
create: (context) => Modular.get<EducationBloc>()),
BlocProvider<SubjectBloc>(
create: (context) => Modular.get<SubjectBloc>()),
],
child: MaterialApp(
initialRoute: "/",
Expand Down
11 changes: 11 additions & 0 deletions lib/blocs/education_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_bloc/flutter_bloc.dart';

class EducationBloc extends Bloc<List<Map>, List<Map>> {
@override
List<Map> get initialState => [];

@override
Stream<List<Map>> mapEventToState(List<Map> event) async* {
yield event;
}
}
11 changes: 11 additions & 0 deletions lib/blocs/liked_notes_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_bloc/flutter_bloc.dart';

class LikedNotesBloc extends Bloc<List<Map>, List<Map>> {
@override
List<Map> get initialState => [];

@override
Stream<List<Map>> mapEventToState(List<Map> event) async* {
yield event;
}
}
11 changes: 11 additions & 0 deletions lib/blocs/search_catatan_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_bloc/flutter_bloc.dart';

class SearchCatatanBloc extends Bloc<String, String> {
@override
String get initialState => '';

@override
Stream<String> mapEventToState(String event) async* {
yield event;
}
}
11 changes: 11 additions & 0 deletions lib/blocs/subject_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_bloc/flutter_bloc.dart';

class SubjectBloc extends Bloc<List<Map>, List<Map>> {
@override
List<Map> get initialState => [];

@override
Stream<List<Map>> mapEventToState(List<Map> event) async* {
yield event;
}
}
11 changes: 11 additions & 0 deletions lib/blocs/tab_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_bloc/flutter_bloc.dart';

class TabBloc extends Bloc<int, int> {
@override
int get initialState => 0;

@override
Stream<int> mapEventToState(int event) async* {
yield event;
}
}
242 changes: 242 additions & 0 deletions lib/components/Cards/card_note.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:unord/blocs/liked_notes_bloc.dart';
import 'package:unord/data/constants.dart';
import 'package:unord/services/note_service.dart';

class NoteCard extends StatefulWidget {
const NoteCard({
Key key,
this.data,
}) : super(key: key);

final Map data;

@override
_NoteCardState createState() => _NoteCardState();
}

class _NoteCardState extends State<NoteCard> {
int likes = 0;
@override
void initState() {
likes = widget.data['note_likes'].length;
super.initState();
}

void toggleLike(List<Map> listLiked) async {
bool isLiked = listLiked
.where((element) => element['id_catatan'] == widget.data['id'])
.toList()
.length >
0;

if (isLiked) {
if (await NoteService().unlike(widget.data['id'])) {
setState(() {
likes -= 1;
});
}
} else {
if (await NoteService().like(widget.data['id']))
setState(() {
likes += 1;
});
}
}

@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
width: 1,
color: Color(0xFFD8D8D8),
),
),
child: InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () {
print('printed root');
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 14, vertical: 10),
width: MediaQuery.of(context).size.width,
child: Column(
children: [
Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(33),
child: Container(
width: 33,
height: 33,
child: widget.data['user']['image'] != null
? CachedNetworkImage(
imageUrl: URLs.host
.substring(0, URLs.host.length - 1) +
widget.data['user']['image']['formats']
['thumbnail']['url'],
fit: BoxFit.cover,
)
: Image.asset(
'assets/images/default_user_icon.png',
fit: BoxFit.cover,
),
),
),
SizedBox(width: 6),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.data['user']['username'],
style: GoogleFonts.poppins(
fontSize: 15,
color: Color(0xFF3C3C3C),
),
),
Text(
widget.data['education']['title'],
style: GoogleFonts.poppins(
fontSize: 12,
color: Color(0xFF9E9A9A),
height: 1,
),
),
],
),
),
],
),
),
SizedBox(height: 10),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width * .48,
decoration: BoxDecoration(
color: Colors.grey[350],
borderRadius: BorderRadius.circular(7),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(7),
child: CachedNetworkImage(
imageUrl: URLs.host.substring(0, URLs.host.length - 1) +
(widget.data['image']['url'] != null
? widget.data['image']['url']
: widget.data['image']['formats']['thumbnail']
['url']),
fit: BoxFit.cover,
),
),
),
SizedBox(height: 10),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
widget.data['title'],
style: GoogleFonts.poppins(
fontSize: 18,
color: Color(0xFF423838),
),
),
Flexible(
fit: FlexFit.loose,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
widget.data['note_views'].length.toString() +
' views',
style: GoogleFonts.poppins(
fontSize: 11.2,
color: Colors.black,
),
),
SizedBox(width: 20),
Text(
DateFormat('d MMMM y').format(DateTime.parse(
widget.data['updated_at'].toString())),
style: GoogleFonts.poppins(
fontSize: 11.2,
color: Color(0xFF5B5B5B),
),
),
],
),
)
],
),
),
SizedBox(height: 10),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
BlocBuilder<LikedNotesBloc, List<Map>>(
builder: (_, listLiked) => GestureDetector(
onTap: () {
toggleLike(listLiked);
},
child: Container(
child: Row(
children: [
Icon(
listLiked
.where((element) =>
element['id_catatan'] ==
widget.data['id'])
.toList()
.length >
0
? Icons.favorite
: Icons.favorite_border,
color: Colors.pink,
),
SizedBox(width: 5),
Text(
likes.toString() + ' likes',
style: GoogleFonts.poppins(
fontSize: 11.2, color: Colors.pink),
),
],
),
),
),
),
SizedBox(width: 15),
Icon(Icons.comment),
SizedBox(width: 5),
Text(
widget.data['note_comments'].length.toString(),
style: GoogleFonts.poppins(
fontSize: 11.2,
color: Colors.black,
),
),
],
),
)
],
),
),
),
),
);
}
}
Loading

0 comments on commit 1195ea8

Please sign in to comment.