import ' package:auto_size_text/auto_size_text.dart ' ;
import ' package:badges/badges.dart ' ;
import ' package:diplomaticquarterapp/config/config.dart ' ;
import ' package:diplomaticquarterapp/core/model/ImagesInfo.dart ' ;
import ' package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart ' ;
import ' package:diplomaticquarterapp/core/viewModels/base_view_model.dart ' ;
import ' package:diplomaticquarterapp/core/viewModels/project_view_model.dart ' ;
import ' package:diplomaticquarterapp/pages/landing/landing_page.dart ' ;
import ' package:diplomaticquarterapp/services/robo_search/event_provider.dart ' ;
import ' package:diplomaticquarterapp/theme/colors.dart ' ;
import ' package:diplomaticquarterapp/uitl/translations_delegate_base.dart ' ;
import ' package:diplomaticquarterapp/uitl/utils_new.dart ' ;
import ' package:diplomaticquarterapp/widgets/progress_indicator/app_loader_widget.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:font_awesome_flutter/font_awesome_flutter.dart ' ;
import ' package:provider/provider.dart ' ;
import ' ../../locator.dart ' ;
import ' ../progress_indicator/app_loader_widget.dart ' ;
import ' arrow_back.dart ' ;
import ' floating_button_search.dart ' ;
import ' network_base_view.dart ' ;
import ' not_auh_page.dart ' ;
VoidCallback _onCartClick ;
class AppScaffold extends StatelessWidget {
final String appBarTitle ;
final Widget body ;
final Widget bottomSheet ;
final Widget bottomNavigationBar ;
final bool isLoading ;
final bool isShowAppBar ;
final bool showNewAppBar ;
final bool showNewAppBarTitle ;
final bool hasAppBarParam ;
final BaseViewModel baseViewModel ;
final bool isBottomBar ;
final Widget floatingActionButton ;
final bool isPharmacy ;
final bool isOfferPackages ;
final bool showPharmacyCart ;
final bool showOfferPackagesCart ;
final String title ;
final String description ;
final bool isShowDecPage ;
final List < String > infoList ;
final Color backgroundColor ;
final double preferredSize ;
final bool showHomeAppBarIcon ;
final List < Widget > appBarIcons ;
final List < ImagesInfo > imagesInfo ;
final bool isHelp ;
final String icon ;
final bool showDropDown ;
final int dropdownIndexValue ;
List < String > dropDownList ;
final Function ( int ) dropDownIndexChange ;
Function onTap ;
AuthenticatedUserObject authenticatedUserObject = locator < AuthenticatedUserObject > ( ) ;
AppBarWidget appBar ;
AppScaffold ( {
@ required this . body ,
this . appBarTitle = ' ' ,
this . isLoading = false ,
this . isShowAppBar = false ,
this . showNewAppBar = false ,
this . showNewAppBarTitle = false ,
this . hasAppBarParam ,
this . bottomSheet ,
this . bottomNavigationBar ,
this . baseViewModel ,
this . floatingActionButton ,
this . isPharmacy = false ,
this . showPharmacyCart = true ,
this . isOfferPackages = false ,
this . showOfferPackagesCart = false ,
this . title ,
this . description ,
this . isShowDecPage = true ,
this . isBottomBar ,
this . backgroundColor ,
this . preferredSize = 0.0 ,
this . appBarIcons ,
this . infoList ,
this . isHelp = false ,
this . icon ,
this . showHomeAppBarIcon = true ,
this . imagesInfo ,
this . showDropDown = false ,
this . dropDownList ,
this . dropdownIndexValue ,
this . dropDownIndexChange ,
this . onTap ,
} ) ;
AppScaffold setOnAppBarCartClick ( VoidCallback onClick ) {
_onCartClick = onClick ;
return this ;
}
@ override
Widget build ( BuildContext context ) {
AppGlobal . context = context ;
bool isUserNotLogin = ( ! Provider . of < ProjectViewModel > ( context , listen: false ) . isLogin & & isShowDecPage ) ;
return Scaffold (
backgroundColor: backgroundColor ? ? Theme . of ( context ) . scaffoldBackgroundColor ,
appBar: isUserNotLogin
? null
: ( showNewAppBar
? NewAppBarWidget (
title: appBarTitle ,
showTitle: showNewAppBarTitle ,
showDropDown: showDropDown ,
dropdownIndexValue: dropdownIndexValue ,
dropDownList: dropDownList ? ? [ ] ,
dropDownIndexChange: dropDownIndexChange ,
appBarIcons: appBarIcons ,
onTap: onTap ,
)
: ( isShowAppBar
? appBar = AppBarWidget (
appBarTitle: appBarTitle ,
appBarIcons: appBarIcons ,
showHomeAppBarIcon: showHomeAppBarIcon ,
isPharmacy: isPharmacy ,
showPharmacyCart: showPharmacyCart ,
isOfferPackages: isOfferPackages ,
showOfferPackagesCart: showOfferPackagesCart ,
isShowDecPage: isShowDecPage ,
)
: null ) ) ,
bottomSheet: bottomSheet ,
body: SafeArea (
top: true ,
bottom: true ,
child: isUserNotLogin
? NotAutPage (
title: title ? ? appBarTitle ,
description: description ,
infoList: infoList ,
imagesInfo: imagesInfo ,
icon: icon ,
)
: baseViewModel ! = null
? NetworkBaseView (
child: buildBodyWidget ( context ) ,
baseViewModel: baseViewModel ,
)
: buildBodyWidget ( context ) ,
) ,
bottomNavigationBar: bottomNavigationBar ,
floatingActionButton: floatingActionButton ,
) ;
}
buildAppLoaderWidget ( bool isLoading ) {
return isLoading ? AppLoaderWidget ( ) : Container ( ) ;
}
buildBodyWidget ( context ) {
return Stack ( children: < Widget > [ body , isHelp = = true ? RobotIcon ( ) : Container ( ) ] ) ;
}
}
class NewAppBarWidget extends StatelessWidget with PreferredSizeWidget {
final bool showTitle ;
final String title ;
final bool showDropDown ;
final int dropdownIndexValue ;
List < String > dropDownList ;
final Function ( int ) dropDownIndexChange ;
final List < Widget > appBarIcons ;
Function onTap ;
NewAppBarWidget ( { Key key , this . showTitle = false , this . showDropDown = false , this . title = " " , this . dropDownList , this . appBarIcons , this . dropdownIndexValue , this . dropDownIndexChange , this . onTap } )
: super ( key: key ) ;
@ override
Widget build ( BuildContext context ) {
ProjectViewModel projectViewModel = Provider . of ( context ) ;
return AppBar (
elevation: 0 ,
backgroundColor: showTitle ? Colors . white : Colors . transparent ,
automaticallyImplyLeading: false ,
title: Row (
children: [
ArrowBack (
onTap: onTap ,
) ,
if ( showTitle )
Expanded (
child: Text (
title ,
maxLines: 1 ,
style: TextStyle (
fontSize: 24 , fontFamily: ( projectViewModel . isArabic ? ' Cairo ' : ' Poppins ' ) , fontWeight: FontWeight . w700 , color: Color ( 0xff2B353E ) , letterSpacing: - 1.44 , height: 35 / 24 ) ,
) ,
) ,
if ( showDropDown )
Container (
decoration: containerRadius ( Color ( 0xFFF7F7F7 ) , 30 ) ,
height: 30 ,
child: DropdownButtonHideUnderline (
child: ButtonTheme (
alignedDropdown: true ,
child: DropdownButton < int > (
iconEnabledColor: CustomColors . grey2 ,
style: TextStyle ( color: CustomColors . lightGreyColor , fontSize: 12 ) ,
dropdownColor: CustomColors . lightGreyColor ,
value: dropdownIndexValue ,
items: [
for ( int i = 0 ; i < dropDownList . length ; i + + )
DropdownMenuItem < int > (
value: i ,
child: AutoSizeText (
dropDownList [ i ] ,
style: TextStyle (
fontSize: 12 ,
fontFamily: ( projectViewModel . isArabic ? ' Cairo ' : ' Poppins ' ) ,
fontWeight: FontWeight . w600 ,
color: Color ( 0xff2B2E31 ) ,
letterSpacing: - . 48 ,
// height: 12 / 18
) ,
) ,
)
] ,
onChanged: dropDownIndexChange ,
underline: Container (
height: 0 ,
) ,
) ,
) ,
) ,
) ,
] ,
) ,
actions: < Widget > [
if ( appBarIcons ! = null ) . . . appBarIcons ,
] ,
) ;
}
@ override
Size get preferredSize = > Size ( double . maxFinite , 60 ) ;
}
class AppBarWidget extends StatefulWidget with PreferredSizeWidget {
final AuthenticatedUserObject authenticatedUserObject = locator < AuthenticatedUserObject > ( ) ;
final String appBarTitle ;
final bool showHomeAppBarIcon ;
final List < Widget > appBarIcons ;
final bool isPharmacy ;
final bool isOfferPackages ;
final bool showPharmacyCart ;
final bool showOfferPackagesCart ;
final bool isShowDecPage ;
Function ( String ) badgeUpdater ;
AppBarWidget (
{ this . appBarTitle ,
this . showHomeAppBarIcon ,
this . appBarIcons ,
this . isPharmacy = true ,
this . showPharmacyCart = true ,
this . isOfferPackages = false ,
this . showOfferPackagesCart = false ,
this . isShowDecPage = true } ) ;
@ override
State < StatefulWidget > createState ( ) = > AppBarWidgetState ( ) ;
@ override
Size get preferredSize = > Size ( double . maxFinite , 60 ) ;
}
String _badgeText = " 0 " ;
class AppBarWidgetState extends State < AppBarWidget > {
String badgeText = " 0 " ;
@ override
Widget build ( BuildContext context ) {
widget . badgeUpdater = badgeUpdateBlock ;
return buildAppBar ( context ) ;
}
badgeUpdateBlock ( String value ) {
setState ( ( ) {
_badgeText = value ;
} ) ;
}
Widget buildAppBar ( BuildContext context ) {
ProjectViewModel projectViewModel = Provider . of ( context ) ;
return AppBar (
elevation: 0 ,
backgroundColor: widget . isPharmacy ? Colors . green : Theme . of ( context ) . appBarTheme . color ,
textTheme: TextTheme (
headline6: TextStyle ( color: Theme . of ( context ) . textTheme . headline1 . color , fontWeight: FontWeight . bold ) ,
) ,
title: Text ( widget . authenticatedUserObject . isLogin | | ! widget . isShowDecPage ? widget . appBarTitle . toUpperCase ( ) : TranslationBase . of ( context ) . serviceInformationTitle ,
style: TextStyle ( fontWeight: FontWeight . bold , color: Theme . of ( context ) . textTheme . headline1 . color , fontFamily: projectViewModel . isArabic ? ' Cairo ' : ' WorkSans ' ) ) ,
leading: Builder (
builder: ( BuildContext context ) {
return ArrowBack ( ) ;
} ,
) ,
centerTitle: true ,
actions: < Widget > [
( widget . isPharmacy & & widget . showPharmacyCart )
? IconButton (
icon: Badge ( badgeContent: Text ( _badgeText ) , child: Icon ( Icons . shopping_cart ) ) ,
color: Colors . white ,
onPressed: ( ) {
Navigator . of ( context ) . popUntil ( ModalRoute . withName ( ' / ' ) ) ;
} )
: Container ( ) ,
( widget . isOfferPackages & & widget . showOfferPackagesCart )
? IconButton (
icon: Badge (
position: BadgePosition . topStart ( top: - 15 , start: - 10 ) ,
badgeContent: Text (
_badgeText ,
style: TextStyle ( fontSize: 9 , color: Colors . white , fontWeight: FontWeight . normal ) ,
) ,
child: Icon ( Icons . shopping_cart ) ) ,
color: Colors . white ,
onPressed: ( ) {
// Cart Click Event
if ( _onCartClick ! = null ) _onCartClick ( ) ;
} )
: Container ( ) ,
if ( widget . showHomeAppBarIcon )
IconButton (
icon: Icon ( FontAwesomeIcons . home ) ,
color: Colors . white ,
onPressed: ( ) {
Navigator . pushAndRemoveUntil ( context , MaterialPageRoute ( builder: ( context ) = > LandingPage ( ) ) , ( Route < dynamic > r ) = > false ) ;
// Cart Click Event
if ( _onCartClick ! = null ) _onCartClick ( ) ;
} ,
) ,
if ( widget . appBarIcons ! = null ) . . . widget . appBarIcons
] ,
) ;
}
@ override
Size get preferredSize = > Size ( double . maxFinite , 60 ) ;
}
class RobotIcon extends StatefulWidget {
@ override
_RobotIcon createState ( ) = > _RobotIcon ( ) ;
}
class _RobotIcon extends State < RobotIcon > {
var event = RobotProvider ( ) ;
bool isAnimation = false ;
@ override
void initState ( ) {
event . controller . stream . listen ( ( p ) {
if ( p [ ' animationEnable ' ] = = ' false ' ) {
if ( this . mounted ) {
setState ( ( ) {
this . isAnimation = false ;
} ) ;
}
} else if ( p [ ' animationEnable ' ] = = ' true ' ) {
if ( this . mounted ) {
setState ( ( ) {
this . isAnimation = true ;
} ) ;
}
}
if ( p [ ' isRobotVisible ' ] = = ' false ' ) {
if ( this . mounted ) {
setState ( ( ) {
if ( IS_VOICE_COMMAND_CLOSED = = true ) {
this . isAnimation = false ;
}
} ) ;
}
}
} ) ;
super . initState ( ) ;
}
@ override
Widget build ( BuildContext context ) {
return Positioned (
child: Column (
children: [
// isAnimation
// ? Container(
// height: 150,
// width: 200,
// padding: EdgeInsets.all(5),
// margin: EdgeInsets.only(right: 35.0, bottom: 0),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
// color: Colors.white,
// boxShadow: [
// BoxShadow(color: Colors.black, spreadRadius: 1),
// ],
// ),
// child: TyperAnimatedTextKit(
// text: Provider.of<ProjectViewModel>(context, listen: false).isArabic == true
// ? "هذه الخدمة تم تصميمها لتتمكن من ربط الملفات الطبية للعائلة بملفك الطبي حتى تتمكن من إدارة سجلاتهم عن طريق تسجيل الدخول إلى ملفك الطبي."
// : "Through this service, you will be able to link your family medical files to your medical file so that you can manage their records by login to your medical file.",
// textLength: Provider.of<ProjectViewModel>(context, listen: false).isArabic == true
// ? "هذه الخدمة تم تصميمها لتتمكن من ربط الملفات الطبية للعائلة بملفك الطبي حتى تتمكن من إدارة سجلاتهم عن طريق تسجيل الدخول إلى ملفك الطبي.".length
// : "Through this service, you will be able to link your family medical files to your medical file so that you can manage their records by login to your medical file."
// .length))
// : Container(),
Stack (
children: [
// isAnimation
// ? Positioned(
// top: 0,
// right: 40,
// child: Container(
// height: 0,
// width: 0,
// decoration: ShapeDecoration(
// color: Colors.grey,
// shape: MessageBorder(reverse: true),
// )))
// : Container(),
FloatingSearchButton ( )
] ,
)
] ,
) ,
right: - 30 ,
bottom: - 15 ) ;
}
// setAnimation() async {
// /// await sharedPref.getBool(IS_ROBOT_VISIBLE) ||
// // var animation =
// // IS_TEXT_COMPLETED == ? true : false;
// }
}