-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display profile data on AppBar and in E-Tiket
- Loading branch information
1 parent
adefb0e
commit edc5feb
Showing
2 changed files
with
166 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,159 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:crypto/crypto.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
import 'package:gasku/cubits/pengguna_masuk.dart'; | ||
import 'package:gasku/models/pengguna.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:qr_flutter/qr_flutter.dart'; | ||
|
||
class MyETiketPage extends StatelessWidget { | ||
const MyETiketPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: Container( | ||
width: MediaQuery.of(context).size.width * 0.9, | ||
height: 620, | ||
padding: EdgeInsets.fromLTRB(25, 0, 25, 25), | ||
decoration: BoxDecoration( | ||
border: Border.all( | ||
color: Theme.of(context).colorScheme.primary, | ||
width: 1.5, | ||
), | ||
borderRadius: BorderRadius.circular(12), | ||
), | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 5), | ||
child: Text( | ||
'E-Tiket\nLPG Bersubsidi', | ||
textAlign: TextAlign.center, | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineLarge | ||
?.copyWith(fontWeight: FontWeight.bold), | ||
return BlocBuilder<PenggunaMasukCubit, Pengguna?>( | ||
builder: (context, state) { | ||
if (state == null) return SizedBox.shrink(); | ||
|
||
final DateTime dateTime = DateTime.now(); | ||
final DateTime monday = | ||
dateTime.subtract(Duration(days: dateTime.weekday - 1)); | ||
|
||
final String formattedMonday = | ||
DateFormat('dd-MM-yyyy').format(monday).toString(); | ||
final String formattedMonday2 = | ||
DateFormat('ddMMyyyy').format(monday).toString(); | ||
|
||
final DateTime expirationDate = monday.add(Duration(days: 6)); | ||
final String formattedExpirationDate = | ||
DateFormat('dd-MM-yyyy').format(expirationDate).toString(); | ||
|
||
final String eTiketUrl = | ||
'${dotenv.env['SERVER_URL']}/konfirmasi-e-tiket/${state.nik}/${sha1.convert(utf8.encode('${state.nik}($formattedMonday)')).toString()}'; | ||
|
||
return Center( | ||
child: Container( | ||
width: MediaQuery.of(context).size.width * 0.9, | ||
height: 620, | ||
padding: EdgeInsets.fromLTRB(25, 0, 25, 25), | ||
decoration: BoxDecoration( | ||
border: Border.all( | ||
color: Theme.of(context).colorScheme.primary, | ||
width: 1.5, | ||
), | ||
borderRadius: BorderRadius.circular(12), | ||
), | ||
Expanded( | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colorScheme.primary, | ||
borderRadius: BorderRadius.circular(12), | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 5), | ||
child: Text( | ||
'E-Tiket\nLPG Bersubsidi', | ||
textAlign: TextAlign.center, | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineLarge | ||
?.copyWith(fontWeight: FontWeight.bold), | ||
), | ||
), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
CircleAvatar( | ||
radius: 37.5, | ||
backgroundColor: Colors.white, | ||
child: CircleAvatar( | ||
foregroundImage: NetworkImage( | ||
'https://avatars.githubusercontent.com/u/74972129?v=4', | ||
), | ||
radius: 36, | ||
), | ||
), | ||
Text( | ||
'Muhammad Daffa Ilhami', | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
style: Theme.of(context).textTheme.titleMedium?.copyWith( | ||
fontWeight: FontWeight.bold, color: Colors.white), | ||
Expanded( | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colorScheme.primary, | ||
borderRadius: BorderRadius.circular(12), | ||
), | ||
Row( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Icon( | ||
Icons.tag, | ||
size: 20, | ||
color: Colors.white, | ||
CircleAvatar( | ||
radius: 37, | ||
backgroundColor: Colors.white, | ||
child: state.foto == null | ||
? CircleAvatar( | ||
radius: 35, | ||
foregroundImage: | ||
AssetImage('assets/default_pfp.jpg'), | ||
) | ||
: CircleAvatar( | ||
radius: 35, | ||
foregroundImage: MemoryImage( | ||
base64Decode(state.foto!), | ||
), | ||
), | ||
), | ||
Text( | ||
'612896192837', | ||
state.nama, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
style: | ||
Theme.of(context).textTheme.labelLarge?.copyWith( | ||
style: Theme.of(context) | ||
.textTheme | ||
.titleMedium | ||
?.copyWith( | ||
fontWeight: FontWeight.bold, | ||
color: Colors.white), | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Icon( | ||
Icons.tag, | ||
size: 20, | ||
color: Colors.white, | ||
), | ||
Text( | ||
state.nik, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
style: Theme.of(context) | ||
.textTheme | ||
.labelLarge | ||
?.copyWith( | ||
color: Colors.white, | ||
), | ||
), | ||
], | ||
), | ||
SizedBox(height: 20), | ||
QrImageView( | ||
data: eTiketUrl, | ||
version: QrVersions.auto, | ||
size: MediaQuery.of(context).size.width * 0.55, | ||
backgroundColor: Colors.white, | ||
), | ||
SizedBox(height: 15), | ||
Text( | ||
'Nomor E-Tiket', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineSmall | ||
?.copyWith(color: Colors.white), | ||
), | ||
Text( | ||
'LPG-$formattedMonday2', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineMedium | ||
?.copyWith( | ||
fontWeight: FontWeight.bold, | ||
color: Colors.white), | ||
), | ||
Text( | ||
'Berlaku sampai $formattedExpirationDate', | ||
style: TextStyle(color: Colors.white), | ||
), | ||
], | ||
), | ||
SizedBox(height: 20), | ||
QrImageView( | ||
data: '1234567890', | ||
version: QrVersions.auto, | ||
size: MediaQuery.of(context).size.width * 0.55, | ||
backgroundColor: Colors.white, | ||
), | ||
SizedBox(height: 15), | ||
Text( | ||
'Nomor E-Tiket', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineSmall | ||
?.copyWith(color: Colors.white), | ||
), | ||
Text( | ||
'LPG-2024APR02', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineMedium | ||
?.copyWith( | ||
fontWeight: FontWeight.bold, color: Colors.white), | ||
), | ||
Text( | ||
'Berlaku sampai 25/04/2024', | ||
style: TextStyle(color: Colors.white), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains 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