Skip to content

Commit

Permalink
Display profile data on AppBar and in E-Tiket
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaffailhami committed Jun 25, 2024
1 parent adefb0e commit edc5feb
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 112 deletions.
219 changes: 131 additions & 88 deletions lib/pages/e_tiket.dart
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),
),
],
),
),
),
],
),
],
),
),
),
);
},
);
}
}
59 changes: 35 additions & 24 deletions lib/pages/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gasku/cubits/pengguna_masuk.dart';
import 'package:gasku/models/pengguna.dart';
import 'package:gasku/pages/beranda.dart';
import 'package:gasku/pages/e_tiket.dart';
import 'package:gasku/pages/profil.dart';
Expand Down Expand Up @@ -30,31 +33,39 @@ class _MyMainPageState extends State<MyMainPage> {
elevation: 5,
shadowColor: Colors.black.withOpacity(0.4),
actions: [
Container(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Muhammad Daffa Ilhami',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
Text(
'612896192837',
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: Theme.of(context).colorScheme.outline,
),
BlocBuilder<PenggunaMasukCubit, Pengguna?>(
builder: (context, state) {
if (state == null) return SizedBox.shrink();

return Container(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
state.nama,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style:
Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
Text(
state.nik,
style:
Theme.of(context).textTheme.labelMedium?.copyWith(
color: Theme.of(context).colorScheme.outline,
),
),
],
),
],
),
),
),
);
},
),
SizedBox(width: 10),
],
Expand Down

0 comments on commit edc5feb

Please sign in to comment.