Skip to content

Commit

Permalink
correções
Browse files Browse the repository at this point in the history
  • Loading branch information
mahseemann committed Nov 28, 2023
1 parent b5b8b1a commit ab4249f
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class EventDetailProvider extends ChangeNotifier {
event.users = users;
}

updateLocation(Location location) {
event.location = location;
}

splitCosts(BuildContext context) async {
if (event.items != null && event.users != null) {
String itemIds = event.items!.map((e) => e.id).join(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class EventDetailRepository {
endpoint:
"event/${event.id}/split?item_ids=${itemIds}&user_ids=${userIds}",
method: "GET");

return splitCostsTransactionsFromJSON(response.response);
} catch (e) {
if (e is ApiError) {
Expand Down
32 changes: 18 additions & 14 deletions lib/features/event_detail/screens/event_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,25 @@ class EventDetailScreen extends StatelessWidget {
},
),
SizedBox(height: 24),
ElasticButton(
child: SizedBox(
height: 210,
child: EventDetailMap(
color: provider.event.color2,
location: provider.event.location,
),
),
onPressed: () async {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
EventMapScreen(EventEditProvider(provider)),
Consumer<EventDetailProvider>(
builder: (context, provider, child) {
return ElasticButton(
child: SizedBox(
height: 210,
child: EventDetailMap(
color: provider.event.color2,
location: provider.event.location,
),
),
onPressed: () async {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
EventMapScreen(EventEditProvider(provider)),
),
);
},
);
},
),
Expand Down
2 changes: 0 additions & 2 deletions lib/features/event_detail/widgets/event_detail_item_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:role/features/event_detail/providers/event_detail_provider.dart';
import 'package:role/features/user_login/providers/user_login_provider.dart';
import 'package:role/models/item.dart';
import 'package:role/shared/utils/utils.dart';
import 'package:role/shared/widgets/container_text.dart';
import 'package:role/shared/widgets/default_user_icon.dart';
import 'package:role/shared/widgets/dismissible_exclusion_background.dart';
import 'package:role/shared/widgets/elastic_button.dart';
import 'package:role/shared/widgets/remote_profile_picture.dart';

class EventDetailItemRow extends StatelessWidget {
const EventDetailItemRow({
Expand Down
8 changes: 4 additions & 4 deletions lib/features/event_detail/widgets/event_detail_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ class EventStyledMap extends StatelessWidget {
]
""";

static const CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(-26.900851, -49.004592),
zoom: 16,
);
CameraPosition get _kGooglePlex => CameraPosition(
target: location.latLng,
zoom: 16,
);

@override
Widget build(BuildContext context) {
Expand Down
7 changes: 7 additions & 0 deletions lib/features/event_edit/providers/event_edit_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:role/features/event_edit/repository/event_edit_repository.dart';
import 'package:role/features/event_detail/providers/event_detail_provider.dart';
import 'package:role/features/event_list/providers/event_list_provider.dart';
import 'package:role/models/event.dart';
import 'package:role/models/location.dart';
import 'package:role/models/user.dart';
import 'package:role/shared/widgets/custom_toast.dart';

Expand Down Expand Up @@ -117,6 +118,12 @@ class EventEditProvider extends ChangeNotifier {
notifyListeners();
}

updateLocation(Location location) {
event.location = location;
notifyListeners();
eventDetailProvider.notifyListeners();
}

Future<bool> showDeletionDialog(BuildContext context) async {
final completer = Completer<bool>();

Expand Down
4 changes: 2 additions & 2 deletions lib/features/event_edit/screens/event_map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class EventMapScreen extends StatelessWidget {
bottomCardTooltip: "confirmar local",
apiKey: apiKey,
onNext: (location_picker.GeocodingResult? result) {
provider.event.location = Location(
provider.updateLocation(Location(
latitude: result!.geometry.location.lat,
longitude: result.geometry.location.lng,
descricao: result.formattedAddress ?? "",
);
));
Navigator.pop(context);
},
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ class ItemDetailProvider extends ChangeNotifier {
get() async {
item = await itemRepository.getItem(item);
transactions = await itemRepository.getTransactions(item);
notifyListeners();
}
}
5 changes: 2 additions & 3 deletions lib/features/split_costs/providers/split_costs_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:pix_flutter/pix_flutter.dart';
import 'package:role/features/split_costs/screens/qr_code_modal.dart';
import 'package:role/models/user.dart';
import 'package:role/shared/widgets/custom_toast.dart';
Expand All @@ -18,7 +17,7 @@ class SplitCostsProvider extends ChangeNotifier {
void showPixScreen(
BuildContext context, SplitCostTransaction transaction) async {
if (transaction.toUser.pixKey != null) {
QRCodeModalPopup(transaction).show(context);
QRCodeModalPopup(transaction, this).show(context);
}
}

Expand Down Expand Up @@ -56,6 +55,6 @@ class SplitCostTransaction {
SplitCostTransaction(
fromUser: User.fromJson(json['from']),
toUser: User.fromJson(json['to']),
amount: json['amount'],
amount: double.tryParse(json["amount"].toString())!,
);
}
8 changes: 3 additions & 5 deletions lib/features/split_costs/screens/qr_code_modal.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'package:flutter/cupertino.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:role/features/split_costs/providers/split_costs_provider.dart';
import 'package:role/models/user.dart';
import 'package:role/shared/widgets/elastic_button.dart';
import 'package:role/shared/widgets/form/form_item_group_title.dart';
import 'package:role/shared/widgets/modal_popup.dart';
import 'package:role/shared/widgets/remote_profile_picture.dart';
import 'package:pix_flutter/pix_flutter.dart';

class QRCodeModalPopup extends StatelessWidget {
final SplitCostTransaction transaction;
late final SplitCostTransaction transaction;
late final SplitCostsProvider provider;

QRCodeModalPopup(this.transaction);
QRCodeModalPopup(this.transaction, this.provider);

PixFlutter get qrPixKey => PixFlutter(
payload: Payload(
Expand All @@ -31,8 +31,6 @@ class QRCodeModalPopup extends StatelessWidget {

@override
Widget build(BuildContext context) {
SplitCostsProvider provider = SplitCostsProvider([]);

const double padding = 22.0;
const double qrCodePadding = 84.0;

Expand Down
3 changes: 1 addition & 2 deletions lib/features/split_costs/screens/split_costs_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:role/features/split_costs/providers/split_costs_provider.dart';
import 'package:role/features/user_detail/providers/user_detail_provider.dart';
import 'package:role/shared/utils/utils.dart';
import 'package:role/shared/widgets/custom_navigation_bar.dart';
import 'package:role/shared/widgets/elastic_button.dart';
import 'package:role/shared/widgets/remote_profile_picture.dart';

class SplitCostsScreen extends StatelessWidget {
late SplitCostsProvider provider;
late final SplitCostsProvider provider;

SplitCostsScreen(List<SplitCostTransaction> transactions) {
this.provider = SplitCostsProvider(transactions);
Expand Down
2 changes: 1 addition & 1 deletion lib/features/usage_report/screens/usage_report_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class UsageReportHeaderDelegate extends SliverPersistentHeaderDelegate {
],
),
SizedBox(height: 8),
ContainerText(text: "Membro desde 2020")
ContainerText(text: "membro desde 2023")
],
),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/features/user_detail/providers/user_detail_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ class UserDetailProvider extends ChangeNotifier {
notifyListeners();
}

void showReport(BuildContext context) async {
await userRepository.getUsageReport();
}

textChanged() {
if (nameController.text != UserLoginProvider.shared.user?.name) {
_changed = true;
Expand Down
7 changes: 7 additions & 0 deletions lib/features/user_detail/widgets/user_detail_options.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:provider/provider.dart';
import 'package:role/features/event_detail/providers/event_detail_provider.dart';
import 'package:role/features/usage_report/screens/usage_report_screen.dart';
import 'package:role/features/user_detail/providers/user_detail_provider.dart';
import 'package:role/shared/widgets/round_button.dart';

class UserDetailOptions extends StatelessWidget {
Expand All @@ -10,6 +13,9 @@ class UserDetailOptions extends StatelessWidget {

@override
Widget build(BuildContext context) {
UserDetailProvider provider =
Provider.of<UserDetailProvider>(context, listen: false);

return Column(
children: <Widget>[
Container(
Expand All @@ -19,6 +25,7 @@ class UserDetailOptions extends StatelessWidget {
children: <Widget>[
RoundButton(
onPressed: () {
provider.showReport(context);
showCupertinoModalBottomSheet(
context: context,
builder: (context) => UsageReportScreen(),
Expand Down
19 changes: 19 additions & 0 deletions lib/features/user_login/repository/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ class UserRepository {
return null;
}

Future<bool?> getUsageReport() async {
try {
final response =
await API().request(endpoint: "user/report", method: "GET");

Map decoded = json.decode(response.response);
print(decoded);
return true;
} catch (e) {
if (e is ApiError) {
print('Error Code: ${e.code}, Message: ${e.message}');
} else {
print('Unknown error occurred: $e');
}
}

return null;
}

Future<String?> uploadImage(File image) async {
try {
final response = await API()
Expand Down
2 changes: 1 addition & 1 deletion lib/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Event implements JSONSerializable {
Location(
latitude: -26.905926949896116,
longitude: -49.07710147997988,
descricao: "IFSC Campus gaspar");
descricao: "IFSC Campus Gaspar");

int get id => _id;

Expand Down
2 changes: 1 addition & 1 deletion lib/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class User implements JSONSerializable {
id: json["id_usuario"],
name: json["nome"],
email: json["email"],
pixKey: json["pixKey"],
pixKey: json["chave_pix"],
profilePhoto: json["foto_de_perfil_url"],
);
}
Expand Down

0 comments on commit ab4249f

Please sign in to comment.