fix MultiBlocProvider
This commit is contained in:
parent
9a426079fb
commit
a1698872e1
|
@ -21,22 +21,19 @@ class HomePageWidget extends StatefulWidget {
|
||||||
class _HomePageWidgetState extends State<HomePageWidget> {
|
class _HomePageWidgetState extends State<HomePageWidget> {
|
||||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_initializePage();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _initializePage() async {
|
|
||||||
await LocalsRepositoryImpl().processLocals(context).whenComplete(() async {
|
|
||||||
context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return MultiBlocProvider(
|
||||||
create: (context) => HomeBloc()..add(HomeEvent()),
|
providers: [
|
||||||
|
BlocProvider<HomeBloc>(
|
||||||
|
create: (context) => HomeBloc()..add(HomeEvent()),
|
||||||
|
),
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => LocalProfileBloc()..add(LocalProfileEvent()),
|
||||||
|
),
|
||||||
|
|
||||||
|
],
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
key: scaffoldKey,
|
key: scaffoldKey,
|
||||||
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
|
|
|
@ -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/backend/api_requests/api_manager.dart';
|
||||||
import 'package:hub/shared/components/molecules/locals/index.dart';
|
import 'package:hub/shared/components/molecules/locals/index.dart';
|
||||||
|
|
||||||
|
@ -17,7 +18,9 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> processLocals(BuildContext context) async {
|
Future<bool> processLocals(BuildContext context) async {
|
||||||
return await remoteDataSource.processLocals(context);
|
final bool response = await remoteDataSource.processLocals(context);
|
||||||
|
context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -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_theme.dart';
|
||||||
import 'package:hub/flutter_flow/flutter_flow_util.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/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/base_storage.dart';
|
||||||
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class LocalProfileComponentWidget extends StatefulWidget {
|
class LocalProfileComponentWidget extends StatefulWidget {
|
||||||
const LocalProfileComponentWidget({super.key});
|
const LocalProfileComponentWidget({super.key});
|
||||||
|
@ -19,110 +21,229 @@ class LocalProfileComponentWidget extends StatefulWidget {
|
||||||
class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidget> {
|
class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidget> {
|
||||||
|
|
||||||
|
|
||||||
|
Future callback() async {
|
||||||
|
await StorageHelper().s(KeychainStorageKey.clientUUID.value, '');
|
||||||
|
await LocalsRepositoryImpl().processLocals(context);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider<LocalProfileBloc>(
|
|
||||||
create: (context) => LocalProfileBloc()..add(LocalProfileEvent()),
|
|
||||||
child: BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
return
|
||||||
builder: (context, state) {
|
StreamBuilder<LicenseStatus>(
|
||||||
|
stream: LicenseRepositoryImpl.stream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
final textScaler = MediaQuery.textScalerOf(context);
|
final textScaler = MediaQuery.textScalerOf(context);
|
||||||
final double baseFontSize = 14.0;
|
final double baseFontSize = 14.0;
|
||||||
final double scaledFontSize = baseFontSize * textScaler.scale(1);
|
final double scaledFontSize = baseFontSize * textScaler.scale(1);
|
||||||
final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize;
|
final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize;
|
||||||
|
|
||||||
return Container(
|
|
||||||
decoration: const BoxDecoration(),
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
child: Align(
|
return const Center(child: CircularProgressIndicator());
|
||||||
alignment: const AlignmentDirectional(0.0, -1.0),
|
} else if (snapshot.hasError) {
|
||||||
child: Material(
|
return Center(child: Text('Error: ${snapshot.error}'));
|
||||||
color: Colors.transparent,
|
} else if (!snapshot.hasData || snapshot.data! == false) {
|
||||||
elevation: 0.0,
|
|
||||||
child: Container(
|
return BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
||||||
width: double.infinity,
|
builder: (context, state) {
|
||||||
height: 119.0,
|
return _buildDefaultLocalProfile(context, limitedFontSize);
|
||||||
decoration: BoxDecoration(
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return _buildAsyncLocalProfile(context, state, limitedFontSize, callback);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
color: FlutterFlowTheme.of(context).primary,
|
||||||
border: Border.all(
|
|
||||||
color: FlutterFlowTheme.of(context).primary,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
),
|
||||||
mainAxisSize: MainAxisSize.max,
|
child: Row(
|
||||||
children: [
|
mainAxisSize: MainAxisSize.max,
|
||||||
Align(
|
children: [
|
||||||
alignment: const AlignmentDirectional(-1.0, 0.0),
|
Align(
|
||||||
child: Padding(
|
alignment: const AlignmentDirectional(-1.0, 0.0),
|
||||||
padding: const EdgeInsets.all(2.0),
|
child: Padding(
|
||||||
child: InkWell(
|
padding: const EdgeInsets.all(2.0),
|
||||||
splashColor: Colors.transparent,
|
child: InkWell(
|
||||||
focusColor: Colors.transparent,
|
splashColor: Colors.transparent,
|
||||||
hoverColor: Colors.transparent,
|
focusColor: Colors.transparent,
|
||||||
highlightColor: Colors.transparent,
|
hoverColor: Colors.transparent,
|
||||||
onTap: () async {
|
highlightColor: Colors.transparent,
|
||||||
await StorageHelper().s(KeychainStorageKey.clientUUID.value, '');
|
onTap: () async {
|
||||||
await LocalsRepositoryImpl().processLocals(context).whenComplete(() async => context.read<LocalProfileBloc>().add(LocalProfileEvent()));
|
await StorageHelper().s(KeychainStorageKey.clientUUID.value, '');
|
||||||
},
|
await LocalsRepositoryImpl().processLocals(context);
|
||||||
child: ClipRRect(
|
},
|
||||||
borderRadius: BorderRadius.circular(200.0),
|
child: ClipRRect(
|
||||||
child: CachedNetworkImage(
|
borderRadius: BorderRadius.circular(200.0),
|
||||||
imageBuilder: (context, imageProvider) => Container(
|
child: CachedNetworkImage(
|
||||||
decoration: BoxDecoration(
|
imageBuilder: (context, imageProvider) => Container(
|
||||||
image: DecorationImage(
|
decoration: BoxDecoration(
|
||||||
image: imageProvider,
|
image: DecorationImage(
|
||||||
fit: BoxFit.cover,
|
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(
|
].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)),
|
||||||
message: valueOrDefault<String>(
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<String>(
|
||||||
|
convertToUppercase(state.cliName),
|
||||||
|
FFLocalizations.of(context).getVariableText(
|
||||||
|
ptText: 'SEM LOCAL VINCULADO',
|
||||||
|
enText: 'NO LINKED LOCAL',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
valueOrDefault<String>(
|
||||||
convertToUppercase(state.cliName),
|
convertToUppercase(state.cliName),
|
||||||
FFLocalizations.of(context).getVariableText(
|
FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'SEM LOCAL VINCULADO',
|
ptText: 'SEM LOCAL VINCULADO',
|
||||||
enText: 'NO LINKED LOCAL',
|
enText: 'NO LINKED LOCAL',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
overflow: TextOverflow.ellipsis,
|
||||||
valueOrDefault<String>(
|
maxLines: 1,
|
||||||
convertToUppercase(state.cliName),
|
style: FlutterFlowTheme.of(context).labelMedium.override(
|
||||||
FFLocalizations.of(context).getVariableText(
|
fontFamily: 'Nunito',
|
||||||
ptText: 'SEM LOCAL VINCULADO',
|
color: FlutterFlowTheme.of(context).info,
|
||||||
enText: 'NO LINKED LOCAL',
|
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)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
);
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:hub/flutter_flow/flutter_flow_theme.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/modules/index.dart';
|
||||||
import 'package:hub/shared/components/molecules/menu/index.dart';
|
import 'package:hub/shared/components/molecules/menu/index.dart';
|
||||||
|
import 'package:hub/shared/utils/loading_util.dart';
|
||||||
|
|
||||||
class MenuViewFactory extends StatelessWidget {
|
class MenuViewFactory extends StatelessWidget {
|
||||||
final MenuView view;
|
final MenuView view;
|
||||||
|
@ -30,7 +31,7 @@ class MenuViewFactory extends StatelessWidget {
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
return Center(child: Text('Error: ${snapshot.error}'));
|
return Center(child: Text('Error: ${snapshot.error}'));
|
||||||
} else if (!snapshot.hasData || snapshot.data! == false) {
|
} else if (!snapshot.hasData || snapshot.data! == false) {
|
||||||
return _buildLoadingIndicator(context);
|
return LoadingUtil.buildLoadingIndicator(context);
|
||||||
}
|
}
|
||||||
return _buildMenuBloc(context);
|
return _buildMenuBloc(context);
|
||||||
},
|
},
|
||||||
|
@ -41,17 +42,7 @@ class MenuViewFactory extends StatelessWidget {
|
||||||
return _buildMenuBloc(context);
|
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) {
|
Widget _buildMenuBloc(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
|
|
|
@ -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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue