fix MultiBlocProvider
This commit is contained in:
parent
9a426079fb
commit
a1698872e1
|
@ -21,22 +21,19 @@ class HomePageWidget extends StatefulWidget {
|
|||
class _HomePageWidgetState extends State<HomePageWidget> {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<HomeBloc>(
|
||||
create: (context) => HomeBloc()..add(HomeEvent()),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => LocalProfileBloc()..add(LocalProfileEvent()),
|
||||
),
|
||||
|
||||
],
|
||||
child: Scaffold(
|
||||
key: scaffoldKey,
|
||||
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/shared/components/molecules/locals/index.dart';
|
||||
|
||||
|
@ -17,7 +18,9 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
|||
|
||||
@override
|
||||
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
|
||||
|
|
|
@ -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,17 +21,52 @@ class LocalProfileComponentWidget extends StatefulWidget {
|
|||
class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidget> {
|
||||
|
||||
|
||||
Future callback() async {
|
||||
await StorageHelper().s(KeychainStorageKey.clientUUID.value, '');
|
||||
await LocalsRepositoryImpl().processLocals(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<LocalProfileBloc>(
|
||||
create: (context) => LocalProfileBloc()..add(LocalProfileEvent()),
|
||||
child: BlocBuilder<LocalProfileBloc, LocalProfileState>(
|
||||
builder: (context, state) {
|
||||
|
||||
|
||||
return
|
||||
StreamBuilder<LicenseStatus>(
|
||||
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<LocalProfileBloc, LocalProfileState>(
|
||||
builder: (context, state) {
|
||||
return _buildDefaultLocalProfile(context, limitedFontSize);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
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(
|
||||
|
@ -60,8 +97,93 @@ class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidge
|
|||
highlightColor: Colors.transparent,
|
||||
onTap: () async {
|
||||
await StorageHelper().s(KeychainStorageKey.clientUUID.value, '');
|
||||
await LocalsRepositoryImpl().processLocals(context).whenComplete(() async => context.read<LocalProfileBloc>().add(LocalProfileEvent()));
|
||||
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: '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'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
].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(
|
||||
|
@ -121,8 +243,7 @@ class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidge
|
|||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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