Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

fix(edit_jar and add_jar forms): fix add category input and value bug #112

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions fude_app/lib/pages/home/home_page_jar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class HomePageJar extends StatelessWidget {
iconSize: 26,
color: Theme.of(context).textTheme.subhead.color,
onPressed: () {
// print('jar pressed, ${jar['id']}');
model.categoryChildren = [];
model.getJarBySelectedId(jar.documentID);
Navigator.push(
context,
Expand All @@ -95,20 +95,22 @@ class HomePageJar extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.add),
iconSize: 70,
color: model.darkTheme
? Color.fromRGBO(40, 40, 40, 1)
: Color.fromRGBO(242, 242, 242, 1),
onPressed: () => Navigator.push(
icon: Icon(Icons.add),
iconSize: 70,
color: model.darkTheme
? Color.fromRGBO(40, 40, 40, 1)
: Color.fromRGBO(242, 242, 242, 1),
onPressed: () {
model.categoryChildren = [];
Navigator.push(
context,
PageTransition(
curve: Curves.linear,
type: PageTransitionType.downToUp,
child: AddJarPage(),
),
),
),
);
}),
Text(
title == null ? jar['title'].toUpperCase() : 'ADD JAR',
style: TextStyle(
Expand Down
14 changes: 12 additions & 2 deletions fude_app/lib/pages/jars/jar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class _JarPageState extends State<JarPage> {
child: AnimatedOpacity(
opacity: _swiperVisible ? 1.0 : 0.0,
duration: Duration(milliseconds: 1000),
child: Text(
child: model.selectedJar.data['categories'].length > 0 ?Text(
'SELECT CATEGORY',
style: TextStyle(
color:
Expand All @@ -229,6 +229,16 @@ class _JarPageState extends State<JarPage> {
letterSpacing: 3,
),
textAlign: TextAlign.center,
) : Text(
"YOU DON'T HAVE ANY CATEGORIES YET",
style: TextStyle(
color:
Theme.of(context).secondaryHeaderColor,
fontWeight: FontWeight.bold,
fontSize: 14,
letterSpacing: 3,
),
textAlign: TextAlign.center,
),
),
),
Expand All @@ -242,7 +252,7 @@ class _JarPageState extends State<JarPage> {
opacity: _swiperVisible ? 1.0 : 0.0,
duration: Duration(milliseconds: 500),
child: PageView.builder(
reverse: true,
reverse: false,
pageSnapping: true,
scrollDirection: Axis.horizontal,
controller: PageController(
Expand Down
27 changes: 17 additions & 10 deletions fude_app/lib/pages/jars/jar_add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AddJarPage extends StatefulWidget {
class _JarPageState extends State<AddJarPage> {
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
int categoryCount = 0;
bool imageSelected = false;
final Map<String, dynamic> _formData = {
'title': '',
'categories': [],
Expand All @@ -31,7 +32,7 @@ class _JarPageState extends State<AddJarPage> {
formKey.currentState.save(); // Save our form now.
print(_formData);
model.addJar(_formData);

Navigator.pop(context);
}
}
Expand All @@ -55,13 +56,17 @@ class _JarPageState extends State<AddJarPage> {
void updateImage(File image) {
print('image: $image');
setState(() {
imageSelected = true;
_formData['image'] = image;
});
}

void updateCategoryCount() {
print(categoryCount);
print('categoryCount: $categoryCount');
setState(() {
if (imageSelected) {
imageSelected = false;
}
categoryCount += 1;
});
}
Expand All @@ -70,6 +75,7 @@ class _JarPageState extends State<AddJarPage> {
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
final double width = MediaQuery.of(context).size.width;
print('Building Jar_Add...');
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {
return Scaffold(
Expand Down Expand Up @@ -102,14 +108,15 @@ class _JarPageState extends State<AddJarPage> {
children: <Widget>[
SizedBox(height: height * 0.04),
AddJarForm(
formKey: formKey,
updateCategory: updateCategory,
updateTitle: updateTitle,
updateImage: updateImage,
updateCategoryCount: updateCategoryCount,
categoryCount: categoryCount,
categories: _formData['categories'],
),
formKey: formKey,
imageSelected: imageSelected,
updateCategory: updateCategory,
updateTitle: updateTitle,
updateImage: updateImage,
updateCategoryCount: updateCategoryCount,
categoryCount: categoryCount,
categories: _formData['categories'],
model: model),
SizedBox(height: height * 0.035),
Row(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down
4 changes: 2 additions & 2 deletions fude_app/lib/pages/jars/jar_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _JarPageState extends State<EditJarPage> {

@override
void initState() {
_waitinForJarData();
_waitingForJarData();

super.initState();
}
Expand Down Expand Up @@ -133,7 +133,7 @@ class _JarPageState extends State<EditJarPage> {
}
}

void _waitinForJarData() {
void _waitingForJarData() {
Timer(Duration(seconds: 1), () {
setState(() {
currentCategories =
Expand Down
3 changes: 2 additions & 1 deletion fude_app/lib/scoped-models/jar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:validators/validators.dart';
import 'package:scoped_model/scoped_model.dart';
Expand All @@ -20,6 +20,7 @@ mixin JarModel on Model {
'categories': []
};
List<dynamic> _usersJars = [];
List<Widget> categoryChildren = [];

bool _isLoading = false;

Expand Down
23 changes: 12 additions & 11 deletions fude_app/lib/widgets/form-inputs/add_jar_category_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class AddJarCategoryField extends StatelessWidget {
final MainModel model;
final List<dynamic> categories;

AddJarCategoryField({
this.hint,
this.enabled,
this.needsAtLeastOneCategory,
this.updateCategory,
this.addCategoryToRemoveList,
this.model,
this.categories
});
AddJarCategoryField(
{this.hint,
this.enabled,
this.needsAtLeastOneCategory,
this.updateCategory,
this.addCategoryToRemoveList,
this.model,
this.categories});
@override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
Expand All @@ -37,7 +36,8 @@ class AddJarCategoryField extends StatelessWidget {
height: height * 0.08,
width: width * 0.55,
child: TextFormField(
controller: TextEditingController(text: hint != "Add Category" ? hint : null),
controller: TextEditingController(
text: hint != "Add Category" ? hint : null),
textAlign: TextAlign.start,
enabled: enabled,
style: TextStyle(
Expand All @@ -62,7 +62,8 @@ class AddJarCategoryField extends StatelessWidget {
),
validator: (String val) {
String finalVal = val.trim();
if (needsAtLeastOneCategory == true || finalVal.isEmpty && categories.length < 1) {
if (needsAtLeastOneCategory == true ||
finalVal.isEmpty && categories.length < 1) {
return 'cannot be blank';
}
},
Expand Down
73 changes: 48 additions & 25 deletions fude_app/lib/widgets/forms/add_jar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fude/widgets/form-inputs/add_jar_name_input.dart';
import 'package:fude/widgets/form-inputs/add_jar_category_input.dart';
import 'package:fude/widgets/form-inputs/image.dart';
import 'package:fude/scoped-models/main.dart';

class AddJarForm extends StatelessWidget {
final GlobalKey formKey;
final int categoryCount;
final bool imageSelected;
final Function updateTitle;
final Function updateCategory;
final Function updateImage;
final Function updateCategoryCount;
final DocumentSnapshot jar;
final List<dynamic> categories;
final MainModel model;

AddJarForm(
{this.formKey,
this.jar,
this.imageSelected,
this.categoryCount,
this.updateTitle,
this.updateCategory,
this.updateImage,
this.updateCategoryCount,
this.categories});
this.categories,
this.model});

Widget _buildFormTitles(String title, BuildContext context) {
return Row(
Expand Down Expand Up @@ -54,25 +59,45 @@ class AddJarForm extends StatelessWidget {
);
}

Column _addCategoryInputs(BuildContext context) {
var children = <Widget>[];
for (var i = 0; i < categoryCount; i++) {
children.add(
Column(
children: <Widget>[
AddJarCategoryField(
hint: 'Add Category',
updateCategory: updateCategory,
enabled: true,
categories: categories,

Column _initialCategoryInput() {
model.categoryChildren.length == 0
? model.categoryChildren.add(
Column(
children: <Widget>[
AddJarCategoryField(
hint: 'Add Category',
updateCategory: updateCategory,
model: model,
enabled: true,
categories: categories,
),
],
),
],
),
);
}
)
: Container();

return Column(
children: children,
children: model.categoryChildren,
);
}

Column _addCategoryInputs() {
model.categoryChildren.add(
Column(
children: <Widget>[
AddJarCategoryField(
hint: 'Add Category',
updateCategory: updateCategory,
model: model,
enabled: true,
categories: categories,
),
],
),
);

return Column(
children: model.categoryChildren,
);
}

Expand All @@ -99,13 +124,11 @@ class AddJarForm extends StatelessWidget {
SizedBox(height: height * 0.035),
_buildFormTitles("CATEGORIES", context),
SizedBox(height: height * 0.01),
AddJarCategoryField(
hint: 'Add Category',
updateCategory: updateCategory,
enabled: true,
categories: categories,
),
categoryCount > 0 ? _addCategoryInputs(context) : Container(),
categoryCount >= 0 && !imageSelected
? _addCategoryInputs()
: Column(
children: model.categoryChildren,
),
SizedBox(height: height * 0.035),
_buildFormTitles("JAR IMAGE", context),
SizedBox(height: height * 0.03),
Expand Down
32 changes: 15 additions & 17 deletions fude_app/lib/widgets/forms/edit_jar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,22 @@ class EditJarForm extends StatelessWidget {
}

Column _addCategoryInputs() {
var children = <Widget>[];
for (var i = 0; i < categoryCount; i++) {
children.add(
Column(
children: <Widget>[
AddJarCategoryField(
hint: 'Add Category',
updateCategory: updateCategory,
model: model,
enabled: true,
categories: categories,
),
],
),
);
}
model.categoryChildren.add(
Column(
children: <Widget>[
AddJarCategoryField(
hint: 'Add Category',
updateCategory: updateCategory,
model: model,
enabled: true,
categories: categories,
),
],
),
);

return Column(
children: children,
children: model.categoryChildren,
);
}

Expand Down