Skip to content

Commit

Permalink
Naming conventions followed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZikBurns committed Mar 18, 2021
1 parent 3f484af commit 6cb4982
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 127 deletions.
38 changes: 5 additions & 33 deletions lib/adminspecific/activities/activity_form_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_firestore/data/activity.dart';
import 'package:flutter_firestore/data/entity.dart';
import 'package:flutter_firestore/utils/commonfunctions.dart';
import 'file:///C:/Users/ZikBu/Desktop/TFG/FlutterProjects/flutter_firestore/lib/adminspecific/activities/form components.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:provider/provider.dart';
Expand All @@ -19,42 +20,13 @@ class ActivityFormFields extends StatefulWidget {

class _ActivityFormFieldsState extends State<ActivityFormFields> {
List<Entity> entitylist;
List<dynamic> listOfIDs;

List<String> EntitiesToNames(List<Entity> entitylist){
List<String> namelist = new List();
for (var i=0; i<entitylist.length; i++) {
namelist.add(entitylist[i].name);
}
return namelist;
}

List<String> NamestoIDs(List<String> namelist){
List<String> idlist=[];
for (var i=0; i<entitylist.length; i++) {
for (var j=0; j<namelist.length; j++) {
if (namelist[j] == entitylist[i].name) idlist.add(entitylist[i].id);
}
}
return idlist;
}

List<String> IDsToNames(List<String> idlist){
List<String> namelist=[];
for (var i=0; i<entitylist.length; i++) {
for (var j=0; j<idlist.length; j++) {
if (idlist[j] == entitylist[i].id) namelist.add(entitylist[i].name);
}
}
return namelist;
}

FormBuilderCheckboxGroup builderCheckbox(){

final List<String> namelist = EntitiesToNames(entitylist);
final List<String> namelist = CommonFunctions.entitiesToNames(entitylist);
namelist.sort();
if(widget.activity!=null){
List<String> initialcheckedentities=IDsToNames(widget.activity.entities);
List<String> initialcheckedentities=CommonFunctions.iDsToNames(widget.activity.entities,entitylist);
return FormBuilderCheckboxGroup(
initialValue: initialcheckedentities,
name: 'entities',
Expand All @@ -65,7 +37,7 @@ class _ActivityFormFieldsState extends State<ActivityFormFields> {
if((val==null)|| (val.length==0)) return "L'activitat ha de tenir al menys una entitat.";
}
]),
valueTransformer: (val)=> val==null ? val :List<dynamic>.from(NamestoIDs(List<String>.from(val))),
valueTransformer: (val)=> val==null ? val :List<dynamic>.from(CommonFunctions.namestoIDs(List<String>.from(val),entitylist)),
);
}
else{
Expand All @@ -78,7 +50,7 @@ class _ActivityFormFieldsState extends State<ActivityFormFields> {
if((val==null)|| (val.length==0)) return "L'activitat ha de tenir al menys una entitat.";
}
]),
valueTransformer: (val)=> val==null ? val : List<dynamic>.from(NamestoIDs(List<String>.from(val))),
valueTransformer: (val)=> val==null ? val : List<dynamic>.from(CommonFunctions.namestoIDs(List<String>.from(val),entitylist)),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/activities/activity_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class _DetailsPageState extends State<ActivityDetails> {
ActivityService().updateActivity(widget.activity);
}

Future<String> NewImageDialog(BuildContext context){
Future<String> newImageDialog(BuildContext context){
return showDialog(
context: context,
builder: (context){
Expand Down Expand Up @@ -150,7 +150,7 @@ class _DetailsPageState extends State<ActivityDetails> {
FloatingActionButton(
heroTag: "addphototoactivitybutton",
onPressed: () async {
await NewImageDialog(context);
await newImageDialog(context);
(context as Element).reassemble();
},
child: Icon(Icons.broken_image),
Expand Down
25 changes: 12 additions & 13 deletions lib/screens/activities/activity_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ActivityList extends StatefulWidget {

class _State extends State<ActivityList> {
TextEditingController searchController;
String searchtext = null;
String searchtext;
void _onSearch() {
setState(() {
searchtext = searchController.text;
Expand All @@ -35,15 +35,14 @@ class _State extends State<ActivityList> {
@override
Widget build(BuildContext context) {
List<Entity> entitylist= Provider.of<List<Entity>>(context) ?? [];
var list_activities = Provider.of<List<Activity>>(context) ?? [];
list_activities=CommonFunctions.sortActivityPrimes(list_activities);
var listActivities = Provider.of<List<Activity>>(context) ?? [];
listActivities=CommonFunctions.sortActivityPrimes(listActivities);
if(admin.isLoggedIn) {
list_activities = CommonFunctions.applyTypeFilter(list_activities, widget.filter);
listActivities = CommonFunctions.applyTypeFilter(listActivities, widget.filter);
}
else{
print("FIELTROS"+widget.filter+widget.filtermode);
list_activities=CommonFunctions.applyActivityFilters(list_activities,widget.filter,widget.filtermode);
list_activities=CommonFunctions.deleteHiddenActivities(list_activities);
listActivities=CommonFunctions.applyActivityFilters(listActivities,widget.filter,widget.filtermode);
listActivities=CommonFunctions.deleteHiddenActivities(listActivities);
}

return Column(
Expand Down Expand Up @@ -99,29 +98,29 @@ class _State extends State<ActivityList> {
Expanded(
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemCount: list_activities.length,
itemCount: listActivities.length,
itemBuilder: (context, index) {
var act = CommonFunctions.toStringLowerCaseComplete(list_activities[index],entitylist);
var act = CommonFunctions.toStringLowerCaseComplete(listActivities[index],entitylist);
if((searchtext==null)||(act.contains(searchtext.toLowerCase()))){
if (list_activities[index].prime) {
if (listActivities[index].prime) {
return Padding(
padding: const EdgeInsets.only(left: 4.0, right: 4.0,top: 1.0,bottom: 1.0),
child: Card(
shape: new RoundedRectangleBorder(
side: new BorderSide(
color: Colorizer.typecolor(
list_activities[index].type),
listActivities[index].type),
width: 4.0),
borderRadius: BorderRadius.circular(4.0)),
child:ActivityListTile(activity: list_activities[index]),
child:ActivityListTile(activity: listActivities[index]),
));
}
else {

return Padding(
padding: const EdgeInsets.only(left: 4.0, right: 4.0,top: 1.0,bottom: 1.0),
child: Card(
child:ActivityListTile(activity: list_activities[index]))
child:ActivityListTile(activity: listActivities[index]))
);
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/screens/activities/activity_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ class _HomeListTileState extends State<ActivityListTile> {
),
);
} else {
print("ANDREEEEEEEEEEEEEEEEEEEEEEEEEEEEEU");
return Container(
decoration:BoxDecoration(
borderRadius: BorderRadius.all(
Expand Down
9 changes: 4 additions & 5 deletions lib/screens/entities/entity_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _AdminEntityDetailsState
EntityService().updateEntity(widget.entity);
}

Future<String> DeleteImageDialog(BuildContext context) {
Future<String> deleteImageDialog(BuildContext context) {
return showDialog(
context: context,
builder: (context) {
Expand Down Expand Up @@ -114,10 +114,9 @@ class _AdminEntityDetailsState
return FloatingActionButton(
heroTag: "deleteactivitybutton",
onPressed: () async {
var list_activities =
await Provider.of<List<Activity>>(context, listen: false) ?? [];
var listActivities = Provider.of<List<Activity>>(context, listen: false) ?? [];
var canDelete = true;
for (var activity in list_activities) {
for (var activity in listActivities) {
for (var entity in activity.entities) {
if (entity == widget.entity.id) canDelete = false;
}
Expand Down Expand Up @@ -240,7 +239,7 @@ class _AdminEntityDetailsState
: FloatingActionButton(
heroTag: "addphototoactivitybutton",
onPressed: () async {
await DeleteImageDialog(context);
await deleteImageDialog(context);
(context as Element).reassemble();
},
child: Icon(Icons.broken_image),
Expand Down
10 changes: 5 additions & 5 deletions lib/screens/entities/entity_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _EntitiesListState extends State<EntitiesList> {
}
@override
Widget build(BuildContext context) {
var list_entities=Provider.of<List<Entity>>(context) ?? [];
var listEntities=Provider.of<List<Entity>>(context) ?? [];



Expand Down Expand Up @@ -91,17 +91,17 @@ class _EntitiesListState extends State<EntitiesList> {
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: list_entities.length,
itemCount: listEntities.length,
itemBuilder: (context, index) {
var ent = list_entities[index].name.toLowerCase() +
list_entities[index].desc.toLowerCase();
var ent = listEntities[index].name.toLowerCase() +
listEntities[index].desc.toLowerCase();
if ((searchtext == null) ||
(searchtext != null) &&
(ent.contains(searchtext.toLowerCase()))) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Card(
child: EntityListTile(list_entities[index]),
child: EntityListTile(listEntities[index]),
),
);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/screens/entities/entity_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class _HomeListTileState extends State<EntityListTile> {

@override
Widget build(BuildContext context) {
var list_activities=Provider.of<List<Activity>>(context) ?? [];
list_activities = list_activities
var listActivities=Provider.of<List<Activity>>(context) ?? [];
listActivities = listActivities
.where((activity) => activity.entities.contains(widget.entity.id))
.toList();
list_activities.removeWhere((element) => element.visible==false);
listActivities.removeWhere((element) => element.visible==false);
var now = new DateTime.now();
list_activities.removeWhere((element) => element.visibleDate.isBefore(now));
listActivities.removeWhere((element) => element.visibleDate.isBefore(now));

return StreamProvider<List<Activity>>.value(
initialData: [],
Expand All @@ -45,7 +45,7 @@ class _HomeListTileState extends State<EntityListTile> {
),
child: ListTile(
tileColor: Color(0xFFF5F6F9),
title:Text(widget.entity.name+" ("+list_activities.length.toString()+")",style:TextStyle(fontSize: 16.0,fontWeight: FontWeight.bold)),
title:Text(widget.entity.name+" ("+listActivities.length.toString()+")",style:TextStyle(fontSize: 16.0,fontWeight: FontWeight.bold)),
subtitle: Container(
child: Row(
children: [
Expand Down
49 changes: 19 additions & 30 deletions lib/screens/entities/entity_present_activities.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_firestore/data/activity.dart';
import 'package:flutter_firestore/data/entity.dart';
import 'package:flutter_firestore/utils/commonfunctions.dart';
import 'file:///C:/Users/ZikBu/Desktop/TFG/FlutterProjects/flutter_firestore/lib/utils/colorizer.dart';
import 'file:///C:/Users/ZikBu/Desktop/TFG/FlutterProjects/flutter_firestore/lib/screens/activities/activity_list_tile.dart';
import 'package:provider/provider.dart';
Expand All @@ -15,38 +16,26 @@ class EntityPresentActivities extends StatefulWidget {
}

class _State extends State<EntityPresentActivities> {
List<Entity> entitylist;

List<String> IDsToNames(List<String> idlist){
List<String> namelist=[];
for (var i=0; i<entitylist.length; i++) {
for (var j=0; j<idlist.length; j++) {
if (idlist[j] == entitylist[i].id) namelist.add(entitylist[i].name);
}
}
return namelist;
}


@override
Widget build(BuildContext context) {
entitylist= Provider.of<List<Entity>>(context) ?? [];
var list_activities=Provider.of<List<Activity>>(context) ?? [];
List<Entity> entitylist= Provider.of<List<Entity>>(context) ?? [];
var listActivities=Provider.of<List<Activity>>(context) ?? [];
List<Activity> _resultsList=null;
list_activities.sort((a, b) {if(b.prime) return 1; else return -1;});
list_activities.sort((a, b) {if(b.prime) return 1; else return -1;});
listActivities.sort((a, b) {if(b.prime) return 1; else return -1;});
listActivities.sort((a, b) {if(b.prime) return 1; else return -1;});

_resultsList=[];
for(var activity in list_activities){
List<String> entitiesinactivity=IDsToNames(activity.entities);
for(var activity in listActivities){
List<String> entitiesinactivity=CommonFunctions.iDsToNames(activity.entities,entitylist);
for(var entity in entitiesinactivity) {
if (entity == widget.entity.name) {
_resultsList.add(activity);
}
}
}
list_activities=_resultsList;
if(list_activities.isEmpty){
listActivities=_resultsList;
if(listActivities.isEmpty){
return ListTile(
title: Text("Aquesta entitat encara no té activitats programades."),
);
Expand All @@ -55,7 +44,7 @@ class _State extends State<EntityPresentActivities> {
return ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemCount: list_activities.length+1,
itemCount: listActivities.length+1,
itemBuilder: (context,index){
if(index==0){
return ListTile(
Expand All @@ -64,24 +53,24 @@ class _State extends State<EntityPresentActivities> {
}
else{
var now= new DateTime.now();
bool expired= list_activities[index-1].visibleDate.isBefore(now);
if((!admin.isLoggedIn)&&(!list_activities[index-1].visible)) return Container();
else if((!admin.isLoggedIn)&&(list_activities[index-1].visible)){
if((!expired)&&(list_activities[index-1].prime)){
bool expired= listActivities[index-1].visibleDate.isBefore(now);
if((!admin.isLoggedIn)&&(!listActivities[index-1].visible)) return Container();
else if((!admin.isLoggedIn)&&(listActivities[index-1].visible)){
if((!expired)&&(listActivities[index-1].prime)){
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
shape: new RoundedRectangleBorder(
side: new BorderSide(color: Colorizer.typecolor(list_activities[index-1].type), width: 4.0),
side: new BorderSide(color: Colorizer.typecolor(listActivities[index-1].type), width: 4.0),
borderRadius: BorderRadius.circular(4.0)),
child: ActivityListTile(activity: list_activities[index-1])
child: ActivityListTile(activity: listActivities[index-1])
),
);
}
else if((!expired)&&(!list_activities[index-1].prime)){
else if((!expired)&&(!listActivities[index-1].prime)){
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(child: ActivityListTile(activity: list_activities[index-1])),
child: Card(child: ActivityListTile(activity: listActivities[index-1])),
);
}
else return Container();
Expand All @@ -90,7 +79,7 @@ class _State extends State<EntityPresentActivities> {
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
child: ActivityListTile(activity: list_activities[index-1])
child: ActivityListTile(activity: listActivities[index-1])
),
);
}
Expand Down
Loading

0 comments on commit 6cb4982

Please sign in to comment.