Here is an example of a complete profile app code in Flutter that allows the user to view and edit their profile information:
Source Code
/*import 'package:flutter/material.dart';
class ProfilePage extends StatefulWidget {
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State {
String _name = "John Doe";
String _email = "john.doe@example.com";
String _profileImage =
"https://example.com/images/profile.jpg";
bool _isEditing = false;
final _nameController = TextEditingController();
final _emailController = TextEditingController();
@override
void initState() {
super.initState();
_nameController.text = _name;
_emailController.text = _email;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("My Profile"),
actions: [
_isEditing
? IconButton(
icon: Icon(Icons.check),
onPressed: () {
setState(() {
_name = _nameController.text;
_email = _emailController.text;
_isEditing = false;
});
},
)
: IconButton(
icon: Icon(Icons.edit),
onPressed: () {
setState(() {
_isEditing = true;
});
},
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: 50,
backgroundImage: NetworkImage(_profileImage),
),
SizedBox(
height: 10,
),
_isEditing
? TextField(
controller: _nameController,
decoration: InputDecoration(labelText: "Name"),
)
: Text(
_name,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(
height: 10,
),
_isEditing
? TextField(
controller: _emailController,
decoration: InputDecoration(labelText: "Email"),
)
: Text(
_email,
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
SizedBox(
height: 10,
),
_isEditing
? RaisedButton(
child: Text("Save"),
onPressed: () {
setState(() {
_name = _nameController.text;
_email = _emailController.text;
_isEditing = false;
});
},
)
: Container(),
],
),
),
);
}
}*/
Leave a Reply