Skip to content

Commit

Permalink
Finishing (#10)
Browse files Browse the repository at this point in the history
* create models for Artikel and create get-post method

* refactor method get and post

* create myartikel.dart for artikel page

* create artikel_by_id.dart

* create floating action button for tambah artikel

* create form_tambah_artikel.dart for form tambah artikel page

* delete keyboard type in form tambah artikel

* Implement auth: done (#3)

* Init authentication page

* Add bottom navbar

* Implement login and signup UI

* Authentication: done

* edit _bacabund.dart

* add conditional for floating action button in myartikel.dart

* changed widget name into MyArtikel

* add BacaBundPage to routes_factory.dart, but still got an error

* form + list diary

* fixed bug string got null

* fixed bug in models and method get artikel

* change button color into red

* fixed overflow in login page

* fixed overflow in signup page

* date & fetch belom :(

* use the postArtikel method in form page

* styling only without features & fetch

* change the login and signup url & changed models attribute variable names

* trash #1

* create new post method using request.post, but still got an error

* build method get & post but didnt work

* fixed bugs in post artikel

* fixed bugs in button simpan form artikel

* delete unnecessary comments

* add configuration for deployment

* use circular progress indicator while fetching artikel

* add state while fetching data

* fetch data to django without filter

* last revision, failed to fetch with login required

* roles handled, still clueless abt filter-delete-post

* Periksabund ui

* Create Home, Onboarding, and TanyaBund Page (#4)

* Feat: TanyaBund Post Question and Answer (#5)

* Create Home, Onboarding, and TanyaBund Page

* Feat: Implement Functionality to Add Question and Answer

* implement get & post, but not applicable in railway

* add delete method, but still get authentication problem

* new branch

* Temporary commit

* get post

* Commit

* Add Functionality to Delete Question and Answer (#6)

* Create Home, Onboarding, and TanyaBund Page

* Feat: Implement Functionality to Add Question and Answer

* Add Functionality to Delete Question and Answer

* Fix: Conflict

* Finishing TanyaBund

* PeriksaBund Get, Post #1

* solve merge

* Pubspec commit

* change appbar color

* merge development

* delete codes for debugging

* Commit pubspec

* Change Api to Railway

* get, post, delete done :')

* add if else for faskes

* railway

* scrollview

* PeriksaBund Delete Feature #1

* scrollview

* Implementing Logout

* Commit

* PeriksaBund Final

* Add Role Greetings

* Finishing

Co-authored-by: iqbalpa <[email protected]>
Co-authored-by: Mayfa Shadrina Siddi <[email protected]>
Co-authored-by: shafanjw <[email protected]>
Co-authored-by: dionavarastika <[email protected]>
Co-authored-by: Mayfa Shadrina Siddi <[email protected]>
  • Loading branch information
6 people authored Dec 12, 2022
1 parent 8070135 commit 6dcad84
Show file tree
Hide file tree
Showing 31 changed files with 1,071 additions and 316 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:endterm_project/routes/routes_factory.dart';
import 'package:endterm_project/utils/globals/_globals.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pbp_django_auth/pbp_django_auth.dart';
Expand All @@ -18,6 +19,9 @@ class MyApp extends StatelessWidget {
return request;
},
child: MaterialApp(
theme: ThemeData(
primarySwatch: Colors.red,
),
title: 'Flutter Demo',
onGenerateRoute: (settings) {
return MaterialPageRoute<void>(
Expand Down
65 changes: 65 additions & 0 deletions lib/models/diarybund/diary.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// To parse this JSON data, do
//
// final diary = diaryFromJson(jsonString);

import 'dart:convert';

List<Diary> diaryFromJson(String str) => List<Diary>.from(json.decode(str).map((x) => Diary.fromJson(x)));

String diaryToJson(List<Diary> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class Diary {
Diary({
required this.pk,
required this.fields,
});

int pk;
Fields fields;

factory Diary.fromJson(Map<String, dynamic> json) => Diary(
pk: json["pk"],
fields: Fields.fromJson(json["fields"]),
);

Map<String, dynamic> toJson() => {
"pk": pk,
"fields": fields.toJson(),
};
}

class Fields {
Fields({
required this.user,
required this.date,
required this.title,
required this.emotion,
required this.fieldsAbstract,
required this.description,
});

String user;
DateTime date;
String title;
int emotion;
String fieldsAbstract;
String description;

factory Fields.fromJson(Map<String, dynamic> json) => Fields(
user: json["user"],
date: DateTime.parse(json["date"]),
title: json["title"],
emotion: json["emotion"],
fieldsAbstract: json["abstract"],
description: json["description"],
);

Map<String, dynamic> toJson() => {
"user": user,
"date": "${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}",
"title": title,
"emotion": emotion,
"abstract": fieldsAbstract,
"description": description,
};
}
4 changes: 4 additions & 0 deletions lib/routes/routes_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Widget getScreenByName(String name) {
case RoutesName.catatBundForm:
return const CatatForm();
// Add your page here
case RoutesName.diaryBund:
return const DiaryBundPage();
case RoutesName.diaryBundForm:
return const DiaryForm();
case RoutesName.bacaBund:
return const BacaBundPage();
case RoutesName.periksaBund:
Expand Down
1 change: 1 addition & 0 deletions lib/routes/routes_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class RoutesName {
static const tanyaBund = '/tanya_bund';
static const catatBund = '/catat_bund';
static const diaryBund = '/diary_bund';
static const diaryBundForm = '/diary_bund_form';
static const catatBundForm = '/catat_bund_form';
static const bacaBund = '/baca_bund';
static const periksaBund = '/periksa_bund';
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/bacabund/get_artikel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Future<List<Artikel>> getArtikel() async {
'Content-Type': 'application/json',
},
);

print(utf8.decode(response.bodyBytes));

var data = jsonDecode(utf8.decode(response.bodyBytes));
List<Artikel> artikel = [];
for (var d in data) {
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/diarybund/_diarybund.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// import 'dart:js';

import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:endterm_project/models/diarybund/diary.dart';
import 'package:endterm_project/views/pages/diarybund/_diarybund.dart';
import 'package:pbp_django_auth/pbp_django_auth.dart';


part 'get_diary.dart';
part 'post_diary.dart';
part 'delete_diary.dart';
10 changes: 10 additions & 0 deletions lib/utils/diarybund/delete_diary.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
part of '_diarybund.dart';

// Delete JSON data from the specified URL
Future<dynamic> deleteDiary(int pk) async {
final url = Uri.parse('https://halowbund.up.railway.app/diarybund/delete-flutter/$pk');
final headers = {'Content-type': 'application/json'};
final response = await http.delete(url, headers: headers);

return jsonDecode(response.body);
}
28 changes: 28 additions & 0 deletions lib/utils/diarybund/get_diary.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
part of '_diarybund.dart';

Future<List<Diary>> getDiary(String username) async {
var url = Uri.parse('https://halowbund.up.railway.app/diarybund/json-flutter/$username');
var response = await http.get(
url,
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
);

// melakukan decode response menjadi bentuk json
// print(utf8.decode(response.bodyBytes));
var data = jsonDecode(utf8.decode(response.bodyBytes));

// melakukan konversi data json menjadi object Catat
List<Diary> listCatat = [];
for (var d in data) {
// print("masuk");
if (d != null) {
// print("sini");
// print(Diary.fromJson(d));
listCatat.add(Diary.fromJson(d));
}
}
return listCatat;
}
29 changes: 29 additions & 0 deletions lib/utils/diarybund/post_diary.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
part of '_diarybund.dart';

Future<List<Diary>> postDiary(request, String title, String abstract, String description, int emotion, String username, BuildContext context, mounted) async {

final response = await http.post(Uri.parse('https://halowbund.up.railway.app/diarybund/create-ajax-flutter/'),
headers: <String, String>{
'Content-Type': 'application/json;charset=UTF-8'
},
body: jsonEncode(<String, dynamic>{
'username' : username,
'title': title,
'description': description,
'abstract': abstract,
'emotion': emotion,
}));

// melakukan decode response menjadi bentuk json
var data = jsonDecode(utf8.decode(response.bodyBytes));

// melakukan konversi data json menjadi object ToDo
List<Diary> listCatat = [];
for (var d in data) {
if (d != null) {
listCatat.add(Diary.fromJson(d));
}
}
return listCatat;

}
2 changes: 1 addition & 1 deletion lib/utils/globals/app_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class AppColors {
static const Color creamTua = Color(0xFFdbc8ac);
static const Color white = Color(0xFFFFFFFF);
static const Color merahPink = Color(0xFFE16868);
}
}
2 changes: 1 addition & 1 deletion lib/utils/periksabund/get_info.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of '_periksabund.dart';

Future<List<Note>> getNote(request) async {
final response = await request.get('http://10.0.2.2:8000/periksa/getJsonNote/');
final response = await request.get('https://halowbund.up.railway.app/periksa/getJsonNote/');
List<Note> informasi = [];
for (var d in response['data']) {
if (d != null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/periksabund/post_info.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of '_periksabund.dart';

void postNote(request, lokasi, tanggal, waktu, kapasitas_balita, username) async {
final response = await request.post('http://10.0.2.2:8000/periksa/postJsonNote/', {
final response = await request.post('https://halowbund.up.railway.app/periksa/postJsonNote/', {
"username" : username,
"lokasi" : lokasi,
"tanggal" : tanggal,
Expand All @@ -12,7 +12,7 @@ void postNote(request, lokasi, tanggal, waktu, kapasitas_balita, username) async

void deleteInfo(int id) async {
final response = await http.post(
Uri.parse('http://10.0.2.2:8000/periksa/deleteinfo/$id'),
Uri.parse('https://halowbund.up.railway.app/periksa/deleteinfo/$id'),
);
print(response);
}
2 changes: 1 addition & 1 deletion lib/views/pages/_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'catatbund/_catatbund.dart';
export 'diarybund/_diarybund.dart';
export 'homepage/_homepage.dart';
export 'tanyabund/_tanyabund.dart';
export 'periksabund/_periksabund.dart';
export 'periksabund/_periksabund.dart';
1 change: 1 addition & 0 deletions lib/views/pages/authentication/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class _LoginPageState extends State<LoginPage> {
child: ElevatedButton(
onPressed: () {
if (_loginFormKey.currentState!.validate()) {
print(request);
login(request, username, password, context, mounted);
}
},
Expand Down
2 changes: 2 additions & 0 deletions lib/views/pages/bacabund/_bacabund.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:endterm_project/utils/globals/_globals.dart';
import 'package:endterm_project/views/widgets/globals/_globals.dart';
import 'package:flutter/material.dart';
import 'package:endterm_project/utils/bacabund/_bacabund.dart';
import 'package:endterm_project/models/bacabund/artikel.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/views/pages/bacabund/artikel_by_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _DetailArtikelState extends State<DetailArtikel> {
return Scaffold(
appBar: AppBar(
title: const Text('Detail Artikel'),
backgroundColor: Colors.red,
backgroundColor: AppColors.merahMuda,
),
body: Padding(
padding: const EdgeInsets.all(20.0),
Expand Down Expand Up @@ -62,7 +62,7 @@ class _DetailArtikelState extends State<DetailArtikel> {
margin: const EdgeInsets.only(left: 30),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,
backgroundColor: AppColors.merahMuda,
minimumSize: const Size.fromHeight(40), // NEW
),
onPressed: () {
Expand Down
4 changes: 2 additions & 2 deletions lib/views/pages/bacabund/myartikel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class _BacaBundPageState extends State<BacaBundPage> {
return Scaffold(
appBar: AppBar(
title: const Text('BacaBund'),
backgroundColor: Colors.red,
backgroundColor: AppColors.merahMuda,
),
body: FutureBuilder(
future: getArtikel(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return const Center(
child: CircularProgressIndicator(),
child: SpinKitProgressIndicator(),
);
} else if (snapshot.data!.length == 0) {
return const Center(
Expand Down
1 change: 1 addition & 0 deletions lib/views/pages/catatbund/_catatbund.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:endterm_project/views/widgets/globals/_globals.dart';
import 'package:flutter/material.dart';
import 'package:endterm_project/main.dart';
import 'package:flutter/material.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/views/pages/catatbund/listcatat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _CatatBundPageState extends State<CatatBundPage> {
builder: (context, AsyncSnapshot snapshot) {

if (snapshot.data == null) {
return const Center(child: CircularProgressIndicator());
return const Center(child: SpinKitProgressIndicator());
} else {
if (!snapshot.hasData) {
return Column(
Expand Down Expand Up @@ -141,6 +141,7 @@ class _CatatBundPageState extends State<CatatBundPage> {
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [
FloatingActionButton(
backgroundColor: AppColors.merahMuda,
onPressed: () {
Navigator.push(
context,
Expand Down
20 changes: 20 additions & 0 deletions lib/views/pages/diarybund/_diarybund.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:endterm_project/main.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pbp_django_auth/pbp_django_auth.dart';

import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:endterm_project/models/diarybund/diary.dart';

import '../../../utils/_utils.dart';
import '../../../utils/diarybund/_diarybund.dart';
import '../../../routes/routes_name.dart';
import '../../widgets/globals/_globals.dart';
import '../authentication/_authentication.dart';
import '../homepage/_homepage.dart';

part 'listdiary_page.dart';
part 'form.dart';
part 'diary_details.dart';
Loading

0 comments on commit 6dcad84

Please sign in to comment.