Skip to content

Commit

Permalink
Merge pull request #7 from letterbookd/review
Browse files Browse the repository at this point in the history
Update dev branch with latest review layouts
  • Loading branch information
mmalkindi authored Dec 8, 2023
2 parents 9de753c + f5eba59 commit ba66705
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 83 deletions.
25 changes: 13 additions & 12 deletions lib/review/models/review.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// ignore_for_file: non_constant_identifier_names

class Review {
int stars_rating;
int total_rating;
String status_on_review;
String review_text;
class Review{
int starsRating;
int totalRating;
String statusOnReview;
String reviewText;

Review(
this.stars_rating,
this.total_rating,
this.status_on_review,
this.review_text,
);
}

Review(
this.starsRating,
this.totalRating,
this.statusOnReview,
this.reviewText,
);
}
53 changes: 25 additions & 28 deletions lib/review/screens/review_add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@ import 'package:flutter/material.dart';
import 'package:pbp_django_auth/pbp_django_auth.dart';
import 'package:provider/provider.dart';

class ShopFormPage extends StatefulWidget {
const ShopFormPage({super.key});
// Kurang Impor dari modul library
// import 'package:library_module/library_module.dart';

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

@override
State<ShopFormPage> createState() => _ShopFormPageState();
State<AddFormPage> createState() => _AddFormPageState();
}

class _ShopFormPageState extends State<ShopFormPage> {
class _AddFormPageState extends State<AddFormPage> {
final _formKey = GlobalKey<FormState>();
String _statusOnReview = "";
String _statusOnReview = ""; // Get the value from your library module here
int _starsRating = 0;
String _reviewText = "";

void _submitForm() {
if (_formKey.currentState!.validate()) {
// Handle form submission here
print('Status on Review: $_statusOnReview');
print('Stars Rating: $_starsRating');
print('Review Text: $_reviewText');
}
}

@override
Widget build(BuildContext context) {
final request = context.watch<CookieRequest>();
return Scaffold(
appBar: AppBar(
title: const Center(
child: Text(
'Form Tambah Produk',
'Form Tambah Review',
),
),
backgroundColor: Colors.indigo,
Expand All @@ -32,29 +44,19 @@ class _ShopFormPageState extends State<ShopFormPage> {
body: Form(
key: _formKey,
child: SingleChildScrollView(
child:
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
initialValue: _statusOnReview,
readOnly: true,
decoration: InputDecoration(
hintText: "Status on Review",
labelText: "Status on Review",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
onChanged: (String? value) {
setState(() {
_statusOnReview = value!;
});
},
validator: (String? value) {
if (value == null || value.isEmpty) {
return "Shouldn't be Empty!";
}
return null;
},
),
),
Padding(
Expand All @@ -69,7 +71,7 @@ class _ShopFormPageState extends State<ShopFormPage> {
),
onChanged: (String? value) {
setState(() {
_starsRating = int.parse(value!); //tambah variabel price
_starsRating = int.parse(value!);
});
},
validator: (String? value) {
Expand All @@ -95,7 +97,7 @@ class _ShopFormPageState extends State<ShopFormPage> {
),
onChanged: (String? value) {
setState(() {
_reviewText = value!; //tambah variabel description
_reviewText = value!;
});
},
validator: (String? value) {
Expand All @@ -114,13 +116,8 @@ class _ShopFormPageState extends State<ShopFormPage> {
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.indigo),
),
onPressed: () {
if (_formKey.currentState!.validate()) {}
},
child: const Text(
"Save",
style: TextStyle(color: Colors.white),
),
onPressed: _submitForm,
child: const Text('Submit'),
),
),
),
Expand Down
142 changes: 142 additions & 0 deletions lib/review/screens/review_edit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:pbp_django_auth/pbp_django_auth.dart';
import 'package:provider/provider.dart';

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

@override
State<EditFormPage> createState() => _EditFormPageState();
}

class _EditFormPageState extends State<EditFormPage> {
final _formKey = GlobalKey<FormState>();
String _statusOnReview = "";
int _starsRating = 0;
String _reviewText = "";

void _submitForm() {
if (_formKey.currentState!.validate()) {
// Handle form submission here
print('Status on Review: $_statusOnReview');
print('Stars Rating: $_starsRating');
print('Review Text: $_reviewText');
}
}

@override
Widget build(BuildContext context) {
final request = context.watch<CookieRequest>();
return Scaffold(
appBar: AppBar(
title: const Center(
child: Text(
'Form Edit Review',
),
),
backgroundColor: Colors.indigo,
foregroundColor: Colors.white,
),
body: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButtonFormField<String>(
value: _statusOnReview,
decoration: InputDecoration(
labelText: "Status on Review",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
items: <String>[
'FINISHED',
'READING',
'ON HOLD',
'PLANNED',
'DROPPED',
'UNTRACKED'
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
_statusOnReview = newValue!;
});
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
hintText: "Rating",
labelText: "Rating",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
onChanged: (String? value) {
setState(() {
_starsRating = int.parse(value!);
});
},
validator: (String? value) {
if (value == null || value.isEmpty) {
return "Shouldn't be Empty!";
}
if (int.tryParse(value) == null) {
return "Should be an Integer";
}
return null;
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
hintText: "Review Text",
labelText: "Review Text",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
onChanged: (String? value) {
setState(() {
_reviewText = value!;
});
},
validator: (String? value) {
if (value == null || value.isEmpty) {
return "Shouldn't be Empty!";
}
return null;
},
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.indigo),
),
onPressed: _submitForm,
child: const Text('Submit'),
),
),
),
]),
),
),
);
}
}
Loading

0 comments on commit ba66705

Please sign in to comment.