diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 8b254a27..75d1916e 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -21,22 +21,19 @@ class HomePageWidget extends StatefulWidget { class _HomePageWidgetState extends State { final scaffoldKey = GlobalKey(); - @override - void initState() { - super.initState(); - _initializePage(); - } - - Future _initializePage() async { - await LocalsRepositoryImpl().processLocals(context).whenComplete(() async { - context.read().add(LocalProfileEvent()); - }); - } @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => HomeBloc()..add(HomeEvent()), + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => HomeBloc()..add(HomeEvent()), + ), + BlocProvider( + create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), + ), + + ], child: Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 27873228..cd711443 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -1,4 +1,5 @@ -import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; @@ -17,7 +18,9 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future processLocals(BuildContext context) async { - return await remoteDataSource.processLocals(context); + final bool response = await remoteDataSource.processLocals(context); + context.read().add(LocalProfileEvent()); + return response; } @override diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index f5523433..4a54b3fb 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -6,8 +6,10 @@ import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; +import 'package:hub/shared/components/molecules/modules/data/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:provider/provider.dart'; class LocalProfileComponentWidget extends StatefulWidget { const LocalProfileComponentWidget({super.key}); @@ -19,110 +21,229 @@ class LocalProfileComponentWidget extends StatefulWidget { class _LocalProfileComponentWidgetState extends State { + Future callback() async { + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await LocalsRepositoryImpl().processLocals(context); + } + @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), - child: BlocBuilder( - builder: (context, state) { + + + return + StreamBuilder( + stream: LicenseRepositoryImpl.stream, + builder: (context, snapshot) { final textScaler = MediaQuery.textScalerOf(context); final double baseFontSize = 14.0; final double scaledFontSize = baseFontSize * textScaler.scale(1); final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize; + + + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } else if (!snapshot.hasData || snapshot.data! == false) { + + return BlocBuilder( + builder: (context, state) { + return _buildDefaultLocalProfile(context, limitedFontSize); + }, + ); + + + } + + return BlocBuilder( + builder: (context, state) { + return _buildAsyncLocalProfile(context, state, limitedFontSize, callback); + }, + ); + + }, + ); + + } - return Container( - decoration: const BoxDecoration(), - child: Align( - alignment: const AlignmentDirectional(0.0, -1.0), - child: Material( - color: Colors.transparent, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 119.0, - decoration: BoxDecoration( + Container _buildDefaultLocalProfile(BuildContext context, double limitedFontSize) { + return Container( + decoration: const BoxDecoration(), + child: Align( + alignment: const AlignmentDirectional(0.0, -1.0), + child: Material( + color: Colors.transparent, + elevation: 0.0, + child: Container( + width: double.infinity, + height: 119.0, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primary, + border: Border.all( color: FlutterFlowTheme.of(context).primary, - border: Border.all( - color: FlutterFlowTheme.of(context).primary, - ), ), - child: Row( - mainAxisSize: MainAxisSize.max, - children: [ - Align( - alignment: const AlignmentDirectional(-1.0, 0.0), - child: Padding( - padding: const EdgeInsets.all(2.0), - child: InkWell( - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - onTap: () async { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); - await LocalsRepositoryImpl().processLocals(context).whenComplete(() async => context.read().add(LocalProfileEvent())); - }, - child: ClipRRect( - borderRadius: BorderRadius.circular(200.0), - child: CachedNetworkImage( - imageBuilder: (context, imageProvider) => Container( - decoration: BoxDecoration( - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover, - ), + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: const AlignmentDirectional(-1.0, 0.0), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: () async { + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await LocalsRepositoryImpl().processLocals(context); + }, + child: ClipRRect( + borderRadius: BorderRadius.circular(200.0), + child: CachedNetworkImage( + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, ), ), - imageUrl: valueOrDefault('https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', 'assets/images/home.png'), - width: 80.0, - height: 80.0, - fit: BoxFit.cover, - alignment: const Alignment(0.0, 0.0), - placeholder: (context, url) => Image.asset('assets/images/home.png'), - errorListener: (_) => Image.asset('assets/images/home.png'), - errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), ), - )), + imageUrl: 'assets/images/home.png', + width: 80.0, + height: 80.0, + fit: BoxFit.cover, + alignment: const Alignment(0.0, 0.0), + placeholder: (context, url) => Image.asset('assets/images/home.png'), + errorListener: (_) => Image.asset('assets/images/home.png'), + errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), + ), + )), + ), + ), + Expanded( + child: Tooltip( + message: FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + child: Text( + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), ), - Expanded( - child: Tooltip( - message: valueOrDefault( + ), + ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), + ), + ), + ), + ), + ); + } + + Container _buildAsyncLocalProfile(BuildContext context, LocalProfileState state, double limitedFontSize, Future Function() callback) { + return Container( + decoration: const BoxDecoration(), + child: Align( + alignment: const AlignmentDirectional(0.0, -1.0), + child: Material( + color: Colors.transparent, + elevation: 0.0, + child: Container( + width: double.infinity, + height: 119.0, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primary, + border: Border.all( + color: FlutterFlowTheme.of(context).primary, + ), + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: const AlignmentDirectional(-1.0, 0.0), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: callback, + child: ClipRRect( + borderRadius: BorderRadius.circular(200.0), + child: CachedNetworkImage( + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ), + ), + ), + imageUrl: valueOrDefault('https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', 'assets/images/home.png'), + width: 80.0, + height: 80.0, + fit: BoxFit.cover, + alignment: const Alignment(0.0, 0.0), + placeholder: (context, url) => Image.asset('assets/images/home.png'), + errorListener: (_) => Image.asset('assets/images/home.png'), + errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), + ), + )), + ), + ), + Expanded( + child: Tooltip( + message: valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + child: Text( + valueOrDefault( convertToUppercase(state.cliName), FFLocalizations.of(context).getVariableText( ptText: 'SEM LOCAL VINCULADO', enText: 'NO LINKED LOCAL', ), ), - child: Text( - valueOrDefault( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), ), - ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).info, - fontSize: limitedFontSize, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), - ), - ), ), ), - ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), - ), + ), + ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), ), ), ), - ); - }, - ), - ); + ), + ); + + } } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart index 62634c64..23eb2f8c 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/utils/loading_util.dart'; class MenuViewFactory extends StatelessWidget { final MenuView view; @@ -30,7 +31,7 @@ class MenuViewFactory extends StatelessWidget { } else if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } else if (!snapshot.hasData || snapshot.data! == false) { - return _buildLoadingIndicator(context); + return LoadingUtil.buildLoadingIndicator(context); } return _buildMenuBloc(context); }, @@ -41,17 +42,7 @@ class MenuViewFactory extends StatelessWidget { return _buildMenuBloc(context); } - Widget _buildLoadingIndicator(BuildContext context) { - return Center( - child: Padding( - padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), - child: CircularProgressIndicator( - backgroundColor: FlutterFlowTheme.of(navigatorKey.currentContext!).primaryBackground, - color: FlutterFlowTheme.of(navigatorKey.currentContext!).primary, - ), - ), - ); - } + Widget _buildMenuBloc(BuildContext context) { return BlocProvider( diff --git a/lib/shared/utils/loading_util.dart b/lib/shared/utils/loading_util.dart new file mode 100644 index 00000000..d30dfec3 --- /dev/null +++ b/lib/shared/utils/loading_util.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; + +class LoadingUtil { + static Widget buildLoadingIndicator(BuildContext context) { + return Center( + child: Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), + child: CircularProgressIndicator( + backgroundColor: FlutterFlowTheme.of(navigatorKey.currentContext!).primaryBackground, + color: FlutterFlowTheme.of(navigatorKey.currentContext!).primary, + ), + ), + ); + } +} \ No newline at end of file