Skip to content

Commit

Permalink
minro change
Browse files Browse the repository at this point in the history
  • Loading branch information
harshjohar committed Aug 31, 2022
1 parent d2ff9e1 commit 6603e7b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
36 changes: 21 additions & 15 deletions lib/features/home/screens/user_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import 'package:bigbucks/models/person.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

enum UserInteraction { debtor, creditor }

class UserScreen extends ConsumerStatefulWidget {
final String userUid;
const UserScreen({Key? key, required this.userUid}) : super(key: key);
final UserInteraction userInteraction;
const UserScreen(
{Key? key, required this.userUid, required this.userInteraction})
: super(key: key);

static const String routeName = '/user-screen';

Expand Down Expand Up @@ -46,7 +51,6 @@ class _UserScreenState extends ConsumerState<UserScreen> {
],
),
);
void payBack() {}

@override
void initState() {
Expand Down Expand Up @@ -109,19 +113,21 @@ class _UserScreenState extends ConsumerState<UserScreen> {
userDetails.upiID != null
? Text(userDetails.upiID!)
: const Text("No UPI Id"),
ElevatedButton(
onPressed: () async {
final amount = await openDialog();
if (amount != null) {
await ref.read(homeControllerProvider).paidBack(
context,
widget.userUid,
double.parse(amount));
}
setState(() {});
},
child: const Text("Paid"),
),
if (widget.userInteraction == UserInteraction.debtor)
ElevatedButton(
onPressed: () async {
final amount = await openDialog();
if (amount != null) {
// ignore: use_build_context_synchronously
await ref
.read(homeControllerProvider)
.paidBack(context, widget.userUid,
double.parse(amount));
}
setState(() {});
},
child: const Text("Paid"),
),
],
),
],
Expand Down
14 changes: 13 additions & 1 deletion lib/features/home/widgets/list_person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import 'package:flutter/material.dart';

enum Type { debt, credit }

class ListPersonArguments {
final String uid;
final UserInteraction userInteraction;

ListPersonArguments(this.uid, this.userInteraction);
}

class ListPerson extends StatelessWidget {
final String user;
final String money;
Expand All @@ -25,7 +32,12 @@ class ListPerson extends StatelessWidget {
onTap: () {
Navigator.of(context).pushNamed(
UserScreen.routeName,
arguments: otherUserId,
arguments: ListPersonArguments(
otherUserId,
type == Type.debt
? UserInteraction.debtor
: UserInteraction.creditor,
),
);
},
child: Container(
Expand Down
8 changes: 6 additions & 2 deletions lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:bigbucks/features/home/screens/add_debtor.dart';
import 'package:bigbucks/features/home/screens/contacts_screen.dart';
import 'package:bigbucks/features/home/screens/notifications_screen.dart';
import 'package:bigbucks/features/home/screens/user_screen.dart';
import 'package:bigbucks/features/home/widgets/list_person.dart';
import 'package:bigbucks/features/profile/screens/profile_screen.dart';
import 'package:flutter/material.dart';

Expand All @@ -21,8 +22,11 @@ Route<dynamic> generateRoute(RouteSettings settings) {
return MaterialPageRoute(builder: (ctx) => const ProfileScreen());
case (UserScreen.routeName):
return MaterialPageRoute(builder: (ctx) {
final args = settings.arguments as String;
return UserScreen(userUid: args);
final args = settings.arguments as ListPersonArguments;
return UserScreen(
userUid: args.uid,
userInteraction: args.userInteraction,
);
});
case (ContactScreen.routeName):
return MaterialPageRoute(builder: (ctx) => const ContactScreen());
Expand Down

0 comments on commit 6603e7b

Please sign in to comment.