Skip to content

Commit

Permalink
feat: completed feedback screen changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharlock10 committed Apr 1, 2022
1 parent 63e1377 commit 031a77f
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 153 deletions.
2 changes: 1 addition & 1 deletion lib/models/feedback/feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class FeedbackTypes {
return '';
}

static List<String> getFeedbackTypes() {
static List<String> getFeedbackType() {
return [
featureRequest,
suggestion,
Expand Down
19 changes: 16 additions & 3 deletions lib/providers/feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:paladinsedge/utilities/index.dart' as utilities;

class _FeedbackNotifier extends ChangeNotifier {
bool isSubmitting = false;
String description = '';
String selectedFeedbackType = models.FeedbackTypes.featureRequest;
FilePickerResult? selectedImage;

/// Opens the file picker to select images
Expand All @@ -23,17 +25,28 @@ class _FeedbackNotifier extends ChangeNotifier {
utilities.postFrameCallback(notifyListeners);
}

/// Changes feedbackType
void changeDescription(String text) {
description = text;
utilities.postFrameCallback(notifyListeners);
}

/// Changes feedbackType
void changeFeedbackType(String feedbackType) {
selectedFeedbackType = feedbackType;
utilities.postFrameCallback(notifyListeners);
}

/// Submit the feedback
Future<void> submitFeedback(String description) async {
// TODO: Add support for feedback types
Future<void> submitFeedback() async {
isSubmitting = true;
utilities.postFrameCallback(notifyListeners);

final imageUrl = await _uploadImage();

final feedback = models.Feedback(
description: description,
type: models.FeedbackTypes.suggestion,
type: selectedFeedbackType,
imageUrl: imageUrl,
);

Expand Down
67 changes: 14 additions & 53 deletions lib/screens/feedback/feedback.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:paladinsedge/constants.dart' as constants;
import 'package:paladinsedge/providers/index.dart' as providers;
import 'package:paladinsedge/screens/feedback/feedback_description.dart';
import 'package:paladinsedge/screens/feedback/feedback_image.dart';
import 'package:paladinsedge/screens/feedback/feedback_type_selector.dart';
import 'package:paladinsedge/widgets/index.dart' as widgets;

class Feedback extends HookConsumerWidget {
Expand All @@ -15,13 +16,10 @@ class Feedback extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
// Providers
final feedbackProvider = ref.read(providers.feedback);
final selectedImage =
ref.watch(providers.feedback.select((_) => _.selectedImage));
final isSubmitting =
ref.watch(providers.feedback.select((_) => _.isSubmitting));

// Variables
final textController = useTextEditingController();
final description =
ref.watch(providers.feedback.select((_) => _.description));

// Effects
useEffect(
Expand All @@ -35,7 +33,7 @@ class Feedback extends HookConsumerWidget {
// Methods
final onSubmit = useCallback(
() async {
await feedbackProvider.submitFeedback(textController.text);
await feedbackProvider.submitFeedback();
Navigator.of(context).pop();
widgets.showToast(
context: context,
Expand All @@ -56,52 +54,14 @@ class Feedback extends HookConsumerWidget {
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: LayoutBuilder(
builder: (context, constraints) {
// get the image height & width of image
// get the image height & width of textField

final imageWidth = constraints.maxWidth;
final imageHeight =
imageWidth / constants.ImageAspectRatios.feedbackImage;
final textFieldWidth = constraints.maxWidth;

return Column(
children: [
SizedBox(
width: textFieldWidth,
child: Card(
elevation: 10,
clipBehavior: Clip.hardEdge,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: TextField(
minLines: 5,
maxLines: 10,
controller: textController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(10),
border: InputBorder.none,
hintText: 'Write your feedback here...',
),
style: const TextStyle(fontSize: 18),
),
),
),
const SizedBox(height: 15),
FeedbackImage(
imageWidth: imageWidth,
imageHeight:
selectedImage == null ? imageHeight / 2 : imageHeight,
imagePath: selectedImage?.files.first.path,
onPressImage: feedbackProvider.pickFeedbackImage,
),
],
);
},
child: Column(
children: const [
FeedbackTypeSelector(),
SizedBox(height: 15),
FeedbackDescription(),
SizedBox(height: 15),
FeedbackImage(),
],
),
),
const SizedBox(height: 30),
Expand All @@ -114,6 +74,7 @@ class Feedback extends HookConsumerWidget {
: widgets.Button(
label: 'Submit',
onPressed: onSubmit,
disabled: description.length < 10,
),
),
],
Expand Down
59 changes: 59 additions & 0 deletions lib/screens/feedback/feedback_description.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:paladinsedge/providers/index.dart' as providers;

class FeedbackDescription extends ConsumerWidget {
const FeedbackDescription({Key? key}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
// Providers
final feedbackProvider = ref.read(providers.feedback);

return Card(
elevation: 10,
clipBehavior: Clip.hardEdge,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
margin: const EdgeInsets.symmetric(horizontal: 15),
alignment: Alignment.centerLeft,
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
width: 1,
color: Colors.grey,
),
),
),
child: const Text(
'Description',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
TextField(
minLines: 5,
maxLines: 10,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.symmetric(horizontal: 15, vertical: 10),
border: InputBorder.none,
hintText: 'Write your feedback here...',
),
style: const TextStyle(fontSize: 18),
onChanged: feedbackProvider.changeDescription,
),
],
),
);
}
}
Loading

0 comments on commit 031a77f

Please sign in to comment.