Files
syncrow-app/lib/features/menu/view/widgets/profile/profile_tab.dart
T
2024-07-23 16:16:31 +03:00

99 lines
3.5 KiB
Dart

import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
import 'package:syncrow_app/features/menu/view/widgets/profile/profile_view.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
class ProfileTab extends StatelessWidget {
final String? name;
const ProfileTab({super.key, this.name});
@override
Widget build(BuildContext context) {
return BlocBuilder<AuthCubit, AuthState>(
builder: (context, state) {
final user = AuthCubit.user;
Uint8List? imageBytes;
if (user!.profilePicture != null) {
final base64String = user.profilePicture!;
final startIndex = base64String.indexOf('base64,') + 7;
final pureBase64String = base64String.substring(startIndex);
imageBytes = base64.decode(pureBase64String);
}
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: InkWell(
onTap: () {
Navigator.of(context)
.push(
MaterialPageRoute(
builder: (context) => const ProfileView(),
),
)
.then((result) {
if (result == true) {
context.read<AuthCubit>().fetchUserInfo();
}
});
},
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 20),
DefaultContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
BodyMedium(
text: '${user.firstName!} ',
fontWeight: FontWeight.bold,
),
BodyMedium(
text: user.lastName!,
fontWeight: FontWeight.bold,
),
],
),
const BodySmall(text: "Syncrow Account"),
],
),
),
],
),
Positioned(
right: 20,
top: 0,
child: CircleAvatar(
radius: 38,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 37,
backgroundColor: Colors.grey,
child: ClipOval(
child: Image.memory(
imageBytes!,
fit: BoxFit.cover,
width: 110, // You can adjust the width and height as needed
height: 110,
)),
),
),
),
],
),
),
);
},
);
}
}