Created
November 3, 2025 06:25
-
-
Save nurrachmat-nr/4798bd8e6f2c41811b1ddc4eebaee6ee to your computer and use it in GitHub Desktop.
ProfileScreen.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| class ProfileScreen extends StatefulWidget { | |
| const ProfileScreen({super.key}); | |
| @override | |
| State<ProfileScreen> createState() => _ProfileScreenState(); | |
| } | |
| class _ProfileScreenState extends State<ProfileScreen> { | |
| // 1. Declare necessary variables | |
| bool isSignedIn = false; | |
| String fullName = ''; // Example name | |
| String userName = ''; // Example username | |
| int favoriteCandiCount = 0; | |
| //5. implementasi fungsi signIn | |
| void signIn() { | |
| setState(() { | |
| isSignedIn = !isSignedIn; | |
| }); | |
| } | |
| //6. implementasi fungsi signOut | |
| void signOut() { | |
| setState(() { | |
| isSignedIn = !isSignedIn; | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Stack( | |
| children: [ | |
| Container( | |
| height: 200, | |
| width: double.infinity, | |
| color: Colors.deepPurple, | |
| ), | |
| Padding( | |
| padding: const EdgeInsets.symmetric(horizontal: 16), | |
| child: Column( | |
| children: [ | |
| Align( | |
| alignment: Alignment.topCenter, | |
| child: Padding( | |
| padding: const EdgeInsets.only(top: 150), // 200 - 50 = 150 | |
| child: Stack( | |
| alignment: Alignment.bottomRight, | |
| children: [ | |
| Container( | |
| decoration: BoxDecoration( | |
| border: Border.all( | |
| color: Colors.deepPurple, | |
| width: 2, | |
| ), | |
| shape: BoxShape.circle, | |
| ), | |
| child: CircleAvatar( | |
| radius: 50, | |
| backgroundImage: | |
| AssetImage('images/placeholder_image.png'), | |
| ), | |
| ), | |
| if (isSignedIn) | |
| IconButton( | |
| onPressed: () {}, | |
| icon: Icon( | |
| Icons.camera_alt, | |
| color: Colors.deepPurple[50], | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| SizedBox(height: 20), | |
| Divider(color: Colors.deepPurple[100]), | |
| SizedBox(height: 4), | |
| Row( | |
| children: [ | |
| SizedBox( | |
| width: MediaQuery.of(context).size.width / 3, | |
| child: Row( | |
| children: [ | |
| Icon(Icons.lock, color: Colors.amber), | |
| SizedBox(width: 8), | |
| Text( | |
| 'Pengguna', | |
| style: TextStyle( | |
| fontSize: 18, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ) | |
| ], | |
| ), | |
| ), | |
| Expanded( | |
| child: Text( | |
| ': $userName', | |
| style: TextStyle(fontSize: 18), | |
| ), | |
| ), | |
| ], | |
| ), | |
| SizedBox(height: 4), | |
| Divider(color: Colors.deepPurple[100]), | |
| SizedBox(height: 4), | |
| Row( | |
| children: [ | |
| SizedBox( | |
| width: MediaQuery.of(context).size.width / 3, | |
| child: Row( | |
| children: [ | |
| Icon(Icons.person, color: Colors.blue), | |
| SizedBox(width: 8), | |
| Text( | |
| 'Nama', | |
| style: TextStyle( | |
| fontSize: 18, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ) | |
| ], | |
| ), | |
| ), | |
| Expanded( | |
| child: Text( | |
| ': $fullName', | |
| style: TextStyle(fontSize: 18), | |
| ), | |
| ), | |
| ], | |
| ), | |
| SizedBox(height: 4), | |
| Divider(color: Colors.deepPurple[100]), | |
| SizedBox(height: 4), | |
| Row( | |
| children: [ | |
| SizedBox( | |
| width: MediaQuery.of(context).size.width / 3, | |
| child: Row( | |
| children: [ | |
| Icon(Icons.favorite, color: Colors.red), | |
| SizedBox(width: 8), | |
| Text( | |
| 'Favorite', | |
| style: TextStyle( | |
| fontSize: 18, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ) | |
| ], | |
| ), | |
| ), | |
| Expanded( | |
| child: Text( | |
| ': $favoriteCandiCount', | |
| style: TextStyle(fontSize: 18), | |
| ), | |
| ), | |
| ], | |
| ), | |
| isSignedIn | |
| ? TextButton(onPressed: signOut, child: Text('Sign Out')) | |
| : TextButton(onPressed: signIn, child: Text('Sign In')), | |
| ], | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment