Untitled
unknown
plain_text
2 years ago
4.6 kB
13
Indexable
class HomeScreenHeader extends HookWidget {
const HomeScreenHeader({
Key? key,
}) : super(key: key);
static final imageCubit = getIt<SpsChecklistImageCubit>();
@override
Widget build(BuildContext context) {
useEffect(() {
imageCubit.getToken();
return;
}, []);
var localStorage = getIt<LocalStorage>();
var widgetHeight = useState<double>(0);
var user = useState<dynamic>(null);
var authToken = useState<String?>('');
Future<dynamic> getUserLocal() async {
var box = await localStorage.box('user');
var user = box.get('user');
return user;
}
Future<String> getToken() async {
var token = await getIt<AuthLocalDataSource>().getAccessToken();
return token;
}
useEffect(() {
getToken().then((value) => authToken.value = value);
getUserLocal().then((value) => user.value = value);
}, []);
return BlocBuilder<UserCubit, UserState>(
builder: (context, state) {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
/* Avatar */
Container(
height: widgetHeight.value,
width: widgetHeight.value,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 1.5.sp,
),
),
child: ClipOval(
child: state.user?.userFile?.isNotEmpty ?? user.value?['userFile'].isNotEmpty
? Image.network(
'${NetworkURL.base}/data/gambar/${user.value?['userFile'][0]['path']}',
headers: {
'cookie': 'key=${authToken.value}',
'referer': 'survey.ops'
},
)
: const Icon(
AppIcons.account,
color: Colors.black,
),
),
),
SizedBox(width: 12.w),
/* Text */
SizeFinder(
onChange: (value) => widgetHeight.value = value.height,
child: Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/* Name */
Text(
state.user?.name ?? user.value?['nama'],
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppFont.headline2,
strutStyle: StrutStyle(
forceStrutHeight: true,
fontSize: 22.sp,
),
),
SizedBox(height: 4.h),
/* Rating */
Container(
padding: EdgeInsets.symmetric(
horizontal: 14.w,
vertical: 5.h,
),
decoration: BoxDecoration(
color: AppColor.yellow,
borderRadius: BorderRadius.circular(200),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Gold',
style: AppFont.bodyText2.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w700,
fontSize: 15.sp,
),
strutStyle: StrutStyle(
forceStrutHeight: true,
fontSize: 15.sp,
),
),
SizedBox(width: 4.w),
/* Stars */
...List.generate(
5,
(index) => Icon(
Icons.star,
color: Colors.white,
size: 18.sp,
),
).toList(),
],
),
),
],
),
),
)
],
);
},
);
}
}Editor is loading...