fix attachment error and display image in basic info

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-09-05 16:44:48 +08:00
parent d80b36ed8f
commit 5b8a67131f
10 changed files with 82 additions and 42 deletions

View File

@ -219,8 +219,7 @@ class EducationBloc extends Bloc<EducationEvent, EducationState> {
} }
}); });
on<EducationViewAttachment>((event, emit) { on<EducationViewAttachment>((event, emit) {
String fileUrl = String fileUrl = '${Url.instance.prefixHost()}://${Url.instance.host()}/media/${event.source}';
'${Url.instance.prefixHost()}://${Url.instance.host()}${event.source}';
emit(EducationAttachmentViewState( emit(EducationAttachmentViewState(
fileUrl: fileUrl, fileName: event.fileName)); fileUrl: fileUrl, fileName: event.fileName));
}); });

View File

@ -290,7 +290,7 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
} }
}); });
on<EligibiltyViewAttachmentEvent>((event,emit){ on<EligibiltyViewAttachmentEvent>((event,emit){
String fileUrl = '${Url.instance.prefixHost()}://${Url.instance.host()}${event.source}'; String fileUrl = '${Url.instance.prefixHost()}://${Url.instance.host()}/media/${event.source}';
emit(EligibilityAttachmentViewState(fileUrl: fileUrl,fileName: event.filename)); emit(EligibilityAttachmentViewState(fileUrl: fileUrl,fileName: event.filename));
}); });
on<ShareAttachment>((event, emit) async { on<ShareAttachment>((event, emit) async {

View File

@ -334,7 +334,7 @@ class LearningDevelopmentBloc
} }
}); });
on<LearningDevelopmentViewAttachmentEvent>((event,emit){ on<LearningDevelopmentViewAttachmentEvent>((event,emit){
String fileUrl = '${Url.instance.prefixHost()}://${Url.instance.host()}${event.source}'; String fileUrl = '${Url.instance.prefixHost()}://${Url.instance.host()}/media/${event.source}';
emit(LearningAndDevelopmentAttachmentViewState(fileUrl: fileUrl, filename: event.filename)); emit(LearningAndDevelopmentAttachmentViewState(fileUrl: fileUrl, filename: event.filename));
}); });
on<ShareAttachment>((event, emit) async { on<ShareAttachment>((event, emit) async {

View File

@ -81,8 +81,8 @@ class _LearningDevelopmentViewAttachmentState
), ),
imageUrl: state.fileUrl, imageUrl: state.fileUrl,
width: double.infinity, width: double.infinity,
height: 220,
fit: BoxFit.cover, fit: BoxFit.fitHeight,
), ),
), ),
); );

View File

@ -1,11 +1,9 @@
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../model/profile/attachment.dart'; import '../../../model/profile/attachment.dart';
import '../../../theme-data.dart/box_shadow.dart'; import '../../../theme-data.dart/box_shadow.dart';
import '../../../theme-data.dart/colors.dart'; import '../../../theme-data.dart/colors.dart';
import '../../../utils/alerts.dart';
class SingleAttachment extends StatelessWidget { class SingleAttachment extends StatelessWidget {
final Function()? onpressed; final Function()? onpressed;
@ -36,9 +34,9 @@ class SingleAttachment extends StatelessWidget {
child: child:
GestureDetector( GestureDetector(
onTap: view, onTap: view,
child: AutoSizeText( child: Text(
attachment.filename!, attachment.filename!,
wrapWords: false,
maxLines: 1, maxLines: 1,
), ),
), ),

View File

@ -264,13 +264,13 @@ class RbacModuleObjectsScreen extends StatelessWidget {
}, },
groupHeaderBuilder: (BuildContext context, int section) { groupHeaderBuilder: (BuildContext context, int section) {
return ListTile( return ListTile(
tileColor: second, tileColor: Colors.white,
title: Text( title: Text(
moduleObjects.keys.toList()[section].toUpperCase(), moduleObjects.keys.toList()[section].toUpperCase(),
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith(color: Colors.white), .copyWith(color: primary,fontWeight: FontWeight.bold),
), ),
); );
}, },

View File

@ -5,10 +5,12 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:search_page/search_page.dart';
import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart'; import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart';
import 'package:unit2/screens/superadmin/role/shared_pop_up_menu.dart'; import 'package:unit2/screens/superadmin/role/shared_pop_up_menu.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/error_state.dart'; import 'package:unit2/widgets/error_state.dart';
import '../../../model/rbac/rbac.dart';
import '../../../theme-data.dart/box_shadow.dart'; import '../../../theme-data.dart/box_shadow.dart';
import '../../../theme-data.dart/btn-style.dart'; import '../../../theme-data.dart/btn-style.dart';
import '../../../theme-data.dart/colors.dart'; import '../../../theme-data.dart/colors.dart';
@ -24,12 +26,38 @@ class RbacRoleScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
List<RBAC> roles = [];
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
title: const Text("Role Screen"), title: const Text("Role Screen"),
actions: [ actions: [
IconButton(
onPressed: () {
showSearch(
context: context,
delegate: SearchPage(
barTheme: ThemeData(cardColor: primary),
builder: (RBAC rbac) {
return ListTile(
title: Text(rbac.name!),
);
},
filter: (RBAC rbac) {
return [rbac.name];
},
failure: const Center(
child: Text("No Role found :("),
),
items: roles,
searchLabel: "Search Role",
suggestion: const Center(
child: Text("Search role by name"),
)),
);
},
icon: const Icon(Icons.search)),
AddLeading(onPressed: () { AddLeading(onPressed: () {
BuildContext parent = context; BuildContext parent = context;
showDialog( showDialog(
@ -174,6 +202,7 @@ class RbacRoleScreen extends StatelessWidget {
final parent = context; final parent = context;
if (state is RoleLoadedState) { if (state is RoleLoadedState) {
if (state.roles.isNotEmpty) { if (state.roles.isNotEmpty) {
roles = state.roles;
return ListView.builder( return ListView.builder(
padding: padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 10), const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
@ -190,20 +219,24 @@ class RbacRoleScreen extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
CircleAvatar(child: Text('${index+1}'),), CircleAvatar(
const SizedBox(width: 12,), child: Text('${index + 1}'),
Flexible( ),
child: Text(state.roles[index].name!, const SizedBox(
style: Theme.of(context) width: 12,
.textTheme ),
.titleMedium! Flexible(
.copyWith( child: Text(state.roles[index].name!,
fontWeight: FontWeight.w500, style: Theme.of(context)
color: primary)), .textTheme
), .titleMedium!
], .copyWith(
)), fontWeight: FontWeight.w500,
color: primary)),
),
],
)),
AppPopupMenu<int>( AppPopupMenu<int>(
offset: const Offset(-10, -10), offset: const Offset(-10, -10),
elevation: 3, elevation: 3,
@ -360,7 +393,8 @@ class RbacRoleScreen extends StatelessWidget {
} }
if (state is RoleErrorState) { if (state is RoleErrorState) {
return SomethingWentWrong( return SomethingWentWrong(
message: state.message, onpressed: () { message: state.message,
onpressed: () {
context.read<RoleBloc>().add(GetRoles()); context.read<RoleBloc>().add(GetRoles());
}); });
} }

View File

@ -262,13 +262,13 @@ class RbacRoleExtendScreen extends StatelessWidget {
}, },
groupHeaderBuilder: (BuildContext context, int section) { groupHeaderBuilder: (BuildContext context, int section) {
return ListTile( return ListTile(
tileColor: second, tileColor: Colors.white,
title: Text( title: Text(
rolesExtend.keys.toList()[section].toUpperCase(), rolesExtend.keys.toList()[section].toUpperCase(),
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith(color: Colors.white), .copyWith(color: primary,fontWeight: FontWeight.bold),
), ),
); );
}, },

View File

@ -252,13 +252,13 @@ class RbacRoleModuleScreen extends StatelessWidget {
}, },
groupHeaderBuilder: (BuildContext context, int section) { groupHeaderBuilder: (BuildContext context, int section) {
return ListTile( return ListTile(
tileColor: second, tileColor: Colors.white,
title: Text( title: Text(
roleModules.keys.toList()[section].toUpperCase(), roleModules.keys.toList()[section].toUpperCase(),
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith(color: Colors.white), .copyWith(color: primary,fontWeight: FontWeight.bold),
), ),
); );
}, },

View File

@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
@ -13,6 +14,7 @@ import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
import '../../../bloc/user/user_bloc.dart'; import '../../../bloc/user/user_bloc.dart';
import '../../../theme-data.dart/colors.dart'; import '../../../theme-data.dart/colors.dart';
import '../../../utils/urls.dart';
import '../../../widgets/splash_screen.dart'; import '../../../widgets/splash_screen.dart';
import '../signature/signature_pad.dart'; import '../signature/signature_pad.dart';
import './components/cover-image.dart'; import './components/cover-image.dart';
@ -29,7 +31,9 @@ class BasicInfo extends StatelessWidget {
child: ProgressHUD( child: ProgressHUD(
child: BlocBuilder<UserBloc, UserState>( child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) { builder: (context, state) {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
String fileUrl = '${Url.instance.prefixHost()}://${Url.instance.host()}/media/${ state.userData!.employeeInfo!.profile!.photoPath!}';
state.userData!.employeeInfo!.profile!.sex!.toUpperCase(); state.userData!.employeeInfo!.profile!.sex!.toUpperCase();
return SafeArea( return SafeArea(
child: Scaffold( child: Scaffold(
@ -47,17 +51,22 @@ class BasicInfo extends StatelessWidget {
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
const CircleAvatar(
radius: 72, CachedNetworkImage(
backgroundColor: Colors.white, imageUrl: fileUrl,
), imageBuilder: (context, imageProvider) => Container(
CircleAvatar( width: 160,
radius: 69, height: 160,
backgroundColor: Colors.grey.shade800, decoration: BoxDecoration(
child: SvgPicture.asset( border: Border.all(color: third,width: 3),
'assets/svgs/male.svg', shape: BoxShape.circle,
), image: DecorationImage(
), image: imageProvider, fit: BoxFit.cover),
),
),
placeholder: (context, url) => const CircularProgressIndicator(),
errorWidget: (context, url, error) =>const Icon(Icons.error),
),
], ],
), ),
), ),