Skip to content

Instantly share code, notes, and snippets.

@e200
Last active December 27, 2019 14:22
Show Gist options
  • Save e200/d5cef8b9a69997bedb3c80ad2e63fab5 to your computer and use it in GitHub Desktop.
Save e200/d5cef8b9a69997bedb3c80ad2e63fab5 to your computer and use it in GitHub Desktop.
class ProfilePage extends StatefulWidget {
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage>
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
TabController _tabController;
@override
void initState() {
_tabController = TabController(length: 2, initialIndex: 0, vsync: this);
super.initState();
}
@override
Widget build(BuildContext context) {
super.build(context);
final _user = _userRepository.user;
return Scaffold(
body: DefaultTabController(
length: 2,
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [
SliverAppBar(
title: Text('Perfil'),
actions: getPopupMenuButton(),
pinned: true,
forceElevated: true,
),
SliverToBoxAdapter(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(15),
child: ProfileAvatar(
width: 130,
height: 130,
imageUrl: (_user['picture'] != null)
? _user['picture']['thumbnails'][2]['url']
: '',
username: _user['full_name'],
onImagePicked: (File image) async {
final _media = await _mediaRepository.upload(image);
final _updatedProfileData = await _userRepository
.update({'picture_id': _media.id});
return _media.thumbnails[2].url;
},
onError: (error) {
print(error);
},
),
),
SizedBox(height: 15),
Text(
_user['full_name'],
style: TextStyle(fontSize: 28),
),
SizedBox(height: 10),
Text(
_user['email'],
style: TextStyle(fontSize: 16, color: Colors.grey),
),
SizedBox(height: 35),
],
),
),
SliverToBoxAdapter(
child: TabBar(
labelColor: Colors.red,
unselectedLabelColor: Colors.grey,
tabs: <Widget>[
Tab(
text: 'Teste1',
),
Tab(
text: 'Teste2',
)
],
),
),
];
},
body: TabBarView(
children: <Widget>[
Column(
children: <Widget>[
ListTile(
title: Text('Nome'),
subtitle: Text(_user['full_name']),
),
ListTile(
title: Text('Número B.I.'),
subtitle: Text(_user['identification_number']),
),
ListTile(
title: Text('Data de nascimento'),
subtitle: Text(_user['birth_date']),
),
ListTile(
title: Text('Naturalidade'),
subtitle: Text(_user['naturality']['name'] +
', ' +
_user['naturality']['city']['name']),
),
ListTile(
title: Text('Género'),
subtitle: Text(_user['genre']['name']),
),
],
),
Text('B'),
],
)
)
)
);
}
List<Widget> getPopupMenuButton() {
return <Widget>[
PopupMenuButton<String>(
icon: Icon(Icons.more_vert),
itemBuilder: (BuildContext context) {
return [
PopupMenuItem(
child: Text('Editar perfil'),
value: 'edit-profile',
),
PopupMenuItem(
child: Text('Terminar sessão'),
value: 'end-session',
),
];
},
onSelected: (item) {
if (item == 'edit-profile') {
//
} else if (item == 'end-session') {
//
}
},
)
];
}
@override
bool get wantKeepAlive => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment