iki ada ucapan selamat datang
This commit is contained in:
parent
d6dd976a69
commit
c07c4e97b9
|
|
@ -26,6 +26,13 @@ class AuthenticationBloc extends Bloc<AuthenticationEvent, AuthenticationState>
|
||||||
emit(AuthenticationState.unauthenticated());
|
emit(AuthenticationState.unauthenticated());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
on<AuthenticationLogoutRequested>((event, emit) async {
|
||||||
|
try {
|
||||||
|
await userRepository.logOut();
|
||||||
|
} catch (_) {
|
||||||
|
// ignore errors here; stream will update state accordingly
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@override
|
@override
|
||||||
Future<void> close() {
|
Future<void> close() {
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,7 @@ class AuthenticationUserChanged extends AuthenticationEvent {
|
||||||
|
|
||||||
const AuthenticationUserChanged(this.user);
|
const AuthenticationUserChanged(this.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AuthenticationLogoutRequested extends AuthenticationEvent {
|
||||||
|
const AuthenticationLogoutRequested();
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fl_chart/fl_chart.dart';
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import '../../../blocs/authentication_bloc/authentication_bloc.dart';
|
||||||
import '../../monitoring/evaporasi_monitoring_screen.dart';
|
import '../../monitoring/evaporasi_monitoring_screen.dart';
|
||||||
import '../../monitoring/wind_speed_monitoring_screen.dart';
|
import '../../monitoring/wind_speed_monitoring_screen.dart';
|
||||||
import '../../monitoring/air_quality_monitoring_screen.dart';
|
import '../../monitoring/air_quality_monitoring_screen.dart';
|
||||||
|
|
@ -21,24 +23,39 @@ class HomeScreen extends StatelessWidget {
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
children: [
|
children: [
|
||||||
// 🔹 HEADER DENGAN AKUN INFO
|
// 🔹 HEADER DENGAN AKUN INFO (dynamic dari AuthenticationBloc)
|
||||||
UserAccountsDrawerHeader(
|
BlocBuilder<AuthenticationBloc, AuthenticationState>(
|
||||||
accountName: const Text(
|
builder: (context, state) {
|
||||||
"Admin Klimatologi",
|
final user = state.user;
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
final displayName = (user != null && user.name.isNotEmpty)
|
||||||
),
|
? user.name
|
||||||
accountEmail: const Text("admin@klimatologi.com"),
|
: 'Pengguna';
|
||||||
currentAccountPicture: CircleAvatar(
|
final email = (user != null && user.email.isNotEmpty)
|
||||||
backgroundColor: Colors.blue,
|
? user.email
|
||||||
child: const Text(
|
: 'Tidak ada email';
|
||||||
"A",
|
final initials = (displayName.isNotEmpty)
|
||||||
style: TextStyle(
|
? displayName.trim().split(' ').map((e) => e.isNotEmpty ? e[0] : '').take(2).join()
|
||||||
fontSize: 24,
|
: 'U';
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.white,
|
return UserAccountsDrawerHeader(
|
||||||
|
accountName: Text(
|
||||||
|
displayName,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
),
|
accountEmail: Text(email),
|
||||||
),
|
currentAccountPicture: CircleAvatar(
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
child: Text(
|
||||||
|
initials.toUpperCase(),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
// 🔹 DASHBOARD MENU
|
// 🔹 DASHBOARD MENU
|
||||||
|
|
@ -80,6 +97,17 @@ class HomeScreen extends StatelessWidget {
|
||||||
"Kualitas Udara",
|
"Kualitas Udara",
|
||||||
Icons.cloud,
|
Icons.cloud,
|
||||||
),
|
),
|
||||||
|
const Divider(),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.logout),
|
||||||
|
title: const Text('Logout'),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.pop(context);
|
||||||
|
// trigger logout via bloc
|
||||||
|
final bloc = context.read<AuthenticationBloc>();
|
||||||
|
bloc.add(const AuthenticationLogoutRequested());
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -92,12 +120,19 @@ class HomeScreen extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
BlocBuilder<AuthenticationBloc, AuthenticationState>(
|
||||||
"Selamat Datang Admin Klimatologi",
|
builder: (context, state) {
|
||||||
style: TextStyle(
|
final name = state.user?.name.isNotEmpty == true
|
||||||
fontSize: 22,
|
? state.user!.name
|
||||||
fontWeight: FontWeight.bold,
|
: 'Pengguna';
|
||||||
),
|
return Text(
|
||||||
|
'Selamat Datang $name',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue