Skip to main content

Profile

Get Profile

GET /driver/user-auth/profile
{
"data": {
"id": "uuid",
"driverName": "Ramesh Kumar",
"phone": "+919876543210",
"email": "ramesh@example.com"
}
}

Update Phone Number

POST /driver/user-auth/update-phone
{
"data": {
"phone": "+919876543299"
}
}

Change PIN

POST /driver/user-auth/change-pin
{
"data": {
"phone": "+919876543210",
"pin": "5678"
}
}

UI — Profile View

class ProfileView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final vm = context.watch<ProfileViewModel>();
final profile = vm.profile;

return Scaffold(
appBar: AppBar(
title: const Text('Profile'),
actions: [
IconButton(
icon: const Icon(Icons.logout),
onPressed: () => vm.logout(),
),
],
),
body: ListView(
children: [
const SizedBox(height: 24),
CircleAvatar(
radius: 50,
backgroundColor: Colors.blue.shade100,
child: Text(
profile.driverName[0].toUpperCase(),
style: const TextStyle(fontSize: 36, color: Colors.blue),
),
),
const SizedBox(height: 16),
Center(child: Text(profile.driverName, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold))),
const SizedBox(height: 32),
ProfileInfoTile(icon: Icons.phone, label: 'Phone', value: profile.phone),
ProfileInfoTile(icon: Icons.email, label: 'Email', value: profile.email),
const Divider(),
ListTile(
leading: const Icon(Icons.lock),
title: const Text('Change PIN'),
trailing: const Icon(Icons.chevron_right),
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const ChangePinView()),
),
),
ListTile(
leading: const Icon(Icons.logout, color: Colors.red),
title: const Text('Logout', style: TextStyle(color: Colors.red)),
onTap: () => vm.logout(),
),
],
),
);
}
}

class ProfileInfoTile extends StatelessWidget {
final IconData icon;
final String label;
final String value;

const ProfileInfoTile({super.key, required this.icon, required this.label, required this.value});

@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(icon, color: Colors.grey),
title: Text(label, style: const TextStyle(fontSize: 12, color: Colors.grey)),
subtitle: Text(value, style: const TextStyle(fontSize: 16)),
);
}
}

UI — Change PIN View

class ChangePinView extends StatefulWidget {
const ChangePinView({super.key});

@override
State<ChangePinView> createState() => _ChangePinViewState();
}

class _ChangePinViewState extends State<ChangePinView> {
String _oldPin = '';
String _newPin = '';

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Change PIN')),
body: Column(
children: [
PinCodeTextField(
length: 4,
onChanged: (v) => _oldPin = v,
decoration: const InputDecoration(labelText: 'Current PIN'),
),
PinCodeTextField(
length: 4,
onChanged: (v) => _newPin = v,
decoration: const InputDecoration(labelText: 'New PIN'),
),
ElevatedButton(
onPressed: _oldPin.length == 4 && _newPin.length == 4
? () => context.read<ProfileViewModel>().changePin(_newPin)
: null,
child: const Text('Change PIN'),
),
],
),
);
}
}