Created
September 25, 2021 08:07
-
-
Save kaka2507/44e6148b44856871dbd9ebc6561657eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:app/base/failure/failure.dart'; | |
import 'package:app/base/widget/custom_app_bar.dart'; | |
import 'package:app/base/widget/loading.dart'; | |
import 'package:app/config/colors.dart'; | |
import 'package:app/config/dimensions.dart'; | |
import 'package:app/config/text_styles.dart'; | |
import 'package:app/utils/failure_helper.dart'; | |
import 'package:equatable/equatable.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
abstract class BlocPageStateFull< | |
bloc extends Bloc<dynamic, state>, | |
state extends Equatable, | |
statefulWidget extends StatefulWidget> extends State<statefulWidget> { | |
final String title; | |
final Color backgroundColor; | |
BlocPageStateFull(this.title, | |
{this.backgroundColor = MyColors.defaultBackgroundColor}); | |
@override | |
Widget build(BuildContext context) { | |
return BlocListener<bloc, state>( | |
listener: (context, state) { | |
listener(context, state); | |
}, | |
child: BlocBuilder<bloc, state>( | |
builder: (context, state) { | |
return getWidget(context, state); | |
}, | |
), | |
); | |
} | |
Widget getAppBar(BuildContext context, Equatable state) { | |
return CustomAppBar(title); | |
} | |
Failure getFailure(Equatable state) { | |
return null; | |
} | |
Widget getErrorBar(BuildContext context, Equatable state) { | |
Failure failure = getFailure(state); | |
if (failure == null) return SizedBox(); | |
return Center( | |
child: Padding( | |
padding: const EdgeInsets.only( | |
top: kNormalSpace, left: kNormalSpace, right: kNormalSpace), | |
child: Text(FailureHelper.message(failure), | |
style: MyTextStyle.error), | |
), | |
); | |
} | |
Widget getTopLoading(BuildContext context, Equatable state) { | |
return LoadingWidget(); | |
} | |
Widget getBottomLoading(BuildContext context, Equatable state) { | |
return LoadingWidget(); | |
} | |
Widget getBody(BuildContext context, Equatable state); | |
Widget getWidget(BuildContext context, Equatable state) { | |
return Scaffold( | |
body: SafeArea( | |
child: Container( | |
color: backgroundColor, | |
child: Column( | |
children: <Widget>[ | |
getAppBar(context, state), | |
getErrorBar(context, state), | |
getTopLoading(context, state), | |
Expanded( | |
child: Padding( | |
padding: EdgeInsets.only(top: kNormalSpace), | |
child: getBody(context, state))), | |
getBottomLoading(context, state), | |
], | |
), | |
), | |
), | |
); | |
} | |
void listener(BuildContext context, Equatable state); | |
bloc getBloc() { | |
return BlocProvider.of<bloc>(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment