can you update this "class _ProfileScreenState extends State {
String _username = '';
final _storage = FlutterSecureStorage();
@override
void initState() {
super.initState();
_getProfile();
}
Future _getProfile() async {
try {
final token = await _storage.read(key: LoginLogic.jwtKey);
final response = await http.get(
Uri.parse('endpointUrl/profile'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token',
'Accept': 'application/json',
},
);
print('Received profile response with status code: ${response.statusCode}');
if (response.statusCode != 200) {
setState(() {
_username = '';
});
} else {
final decodedResponse = json.decode(response.body);
setState(() {
_username = decodedResponse['username'] ?? '';
});
}
} catch (e) {
print(e);
setState(() {
_username = '';
});
if (e is http.Response && json.decode(e.body)['error'] == 'Unauthorized') {
LogoutLogic.logout(context);
}
}
// Call the CheckAssignedEtudiant endpoint
_checkAssignedEtudiant();
}
Future _checkAssignedEtudiant() async {
try {
final token = await _storage.read(key: LoginLogic.jwtKey);
final response = await http.get(
Uri.parse('endpointUrl/checkassignedetudiant'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token',
'Accept': 'application/json',
},
);
if (response.statusCode == 200) {
final decodedResponse = json.decode(response.body);
final bool assigned = decodedResponse['assigned'] ?? false;
if (!assigned) {
// Show AlertDialog with dropdown menu and "Select a class" button
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Select a Class'),
content: DropdownButton<String>(
// Populate dropdown items with class options
items: <String>['Class A', 'Class B', 'Class C'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? selectedClass) {
// Handle dropdown selection
print('Selected Class: $selectedClass');
},
),
actions: [
ElevatedButton(
onPressed: () {
// Handle "Select a class" button tap
// Perform necessary actions with the selected class
Navigator.of(context).pop();
},
child: Text('Select a class'),
),
],
);
},
);
}
}
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Profile'),
actions: [
IconButton(
icon: Icon(Icons.logout),
onPressed: () => LogoutLogic.logout(context),
),
],
),
body: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
CircleAvatar(
backgroundImage: NetworkImage(
'https://example.com/avatar.jpg'), // Replace with actual avatar URL
radius: 50.0,
),
SizedBox(height: 16.0),
Text(
'Welcome, $_username!',
style: Theme.of(context).textTheme.headline6,
),
SizedBox(height: 16.0),
SizedBox(height: 16.0),
],
),
),
),
],
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
child: Text('Menu'),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
),
),
ListTile(
title: const Text('Profile'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: const Text('Afficher mes séances d'aujourd'hui'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const ListerSeances()),
);
},
),
ListTile(
title: Text('Marquer manuellement la présence'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MarquerManuellementPresence()),
);
},
),
ListTile(
title: Text('Créer ma séance'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CreateMySeance()),
);
},
),
ListTile(
title: Text('Créer une séance'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CreateSeance()),
);
},
),
ListTile(
title: Text('Créer un département'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CreateDepartmentScreen()),
);
},
),
ListTile(
title: Text('Créer une classe'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreateClassScreen()),
);
},
),
ListTile(
title: Text('Affecter les étudiants'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AssignStudentsScreen()),
);
},
),
ListTile(
title: Text('Attribuer une matière'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AssignSubjectScreen()),
);
},
),
ListTile(
title: Text('Consulter les présences'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AttendanceScreen()),
);
},
),
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
child: Text('Scan QR Code'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ScanEmptyQRCodeScreen(
endpointUrl: endpointUrl,
),
),
);
},
),
SizedBox(width: 16.0),
ElevatedButton(
child: Text('Generate Empty QR Code'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EmptyQRCodeScreen(
endpointUrl: endpointUrl,
),
),
);
},
),
],
),
);
}
}
" to mimic this "class _ProfileScreenState extends State {
String _username = '';
final _storage = FlutterSecureStorage();
@override
void initState() {
super.initState();
_getProfile();
}
Future _getProfile() async {
try {
final token = await _storage.read(key: LoginLogic.jwtKey);
final response = await http.get(
Uri.parse('endpointUrl/profile'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token',
'Accept': 'application/json',
},
);
print('Received profile response with status code: ${response.statusCode}');
if (response.statusCode != 200) {
setState(() {
_username = '';
});
} else {
final decodedResponse = json.decode(response.body);
setState(() {
_username = decodedResponse['username'] ?? '';
});
}
} catch (e) {
print(e);
setState(() {
_username = '';
});
if (e is http.Response && json.decode(e.body)['error'] == 'Unauthorized') {
LogoutLogic.logout(context);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Profile'),
actions: [
IconButton(
icon: Icon(Icons.logout),
onPressed: () => LogoutLogic.logout(context),
),
],
),
body: Center(
child: _username.isNotEmpty
? UserProfileWidget(
username: _username,
avatarUrl:
'https://mspgh.unimelb.edu.au/__data/assets/image/0011/3576098/Placeholder.jpg')
: CircularProgressIndicator(),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
child: Text('Menu'),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
),
),
ListTile(
title: const Text('Profile'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: const Text('Afficher mes séances d'aujourd'hui'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const ListerSeances()),
);
},
),
ListTile(
title: Text('Marquer manuellement la présence'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MarquerManuellementPresence()),
);
},
),
ListTile(
title: Text('Créer ma séance'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CreateMySeance()),
);
},
),
ListTile(
title: Text('Créer une séance'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CreateSeance()),
);
},
),
ListTile(
title: Text('Créer un département'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CreateDepartmentScreen()),
);
},
),
ListTile(
title: Text('Créer une classe'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreateClassScreen()),
);
},
),
ListTile(
title: Text('Affecter les étudiants'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AssignStudentsScreen()),
);
},
),
ListTile(
title: Text('Attribuer une matière'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AssignSubjectScreen()),
);
},
),
ListTile(
title: Text('Consulter les présences'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AttendanceScreen()),
);
},
),
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
child: Text('Scan QR Code'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ScanEmptyQRCodeScreen(
endpointUrl: endpointUrl,
),
),
);
},
),
SizedBox(width: 16.0),
ElevatedButton(
child: Text('Generate Empty QR Code'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EmptyQRCodeScreen(
endpointUrl: endpointUrl,
),
),
);
},
),
],
),
);
}
}
class UserProfileWidget extends StatelessWidget {
const UserProfileWidget({
Key? key,
required this.username,
required this.avatarUrl,
}) : super(key: key);
final String username;
final String avatarUrl;
@override
Widget build(BuildContext context) {
return Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
CircleAvatar(
backgroundImage: NetworkImage(avatarUrl),
radius: 50.0,
),
SizedBox(height: 16.0),
Text('Welcome, $username!',
style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 16.0),
SizedBox(height: 16.0)
],
),
),
),
],
);
}
}" while keeping the additional functionnalities and provide me with the full code ?