getGeneralAppBar function

AppBar getGeneralAppBar(
  1. BuildContext context,
  2. LocaleProvider localeProvider,
  3. bool goBack
)

Returns an AppBar receiving as an argument the context to access the providers, the localeProvider to implement the language button, and a boolean goBack that indicates if the AppBar should include the arrow icon to go to the previous page.

The AppBar includes a dropdown menu with English and Spanish language: when one is selected, it calls LocaleProvider.setLocale passing the selected language as argument.

Implementation

AppBar getGeneralAppBar(BuildContext context, LocaleProvider localeProvider, bool goBack){
  return AppBar(
    automaticallyImplyLeading: goBack,
    /// The height depends on the constant defined in the constants file
    toolbarHeight: MediaQuery.of(context).size.height / GeneralConstants.toolbarHeightRatio,
    backgroundColor: Colors.white,
    actions:[ Expanded(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          /// Comunidad de Madrid Salud logo
          Flexible(
            child: Padding(
              padding: const EdgeInsets.all(24.0),
              child: Image.asset('assets/images/saludMadridPng.png'),
            ),
          ),
          /// Universidad Politecnica de Madrid logo
          Flexible(
            child: Padding(
              padding: const EdgeInsets.all(2.0),
              child: Image.asset('assets/images/upm.png'),
            ),
          ),
          /// Dropdown button to select the language
          Flexible(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                color: Colors.red,
                child: DropdownButton<Locale>(
                  value: localeProvider.locale,
                  icon: const Padding(
                    padding:  EdgeInsets.all(8.0),
                    child:  Icon(Icons.language, color: Colors.white),
                  ),
                  dropdownColor: Colors.red,
                  /// Assigning language to the localeProvider
                  onChanged: (Locale? newLocale) {
                    if (newLocale != null) {
                      localeProvider.setLocale(newLocale);
                    }
                  },
                  items: const [
                    /// The English language is represented with a USA flag
                    DropdownMenuItem(
                      value: Locale('en'),
                      child: Padding(
                        padding: EdgeInsets.all(8.0),
                        child: Text('πŸ‡ΊπŸ‡Έ',
                            style: TextStyle(color: Colors.white)),
                      ),
                    ),
                    /// The Spanish language is represented with a Spanish flag
                    DropdownMenuItem(
                      value: Locale('es'),
                      child: Padding(
                        padding: EdgeInsets.all(8.0),
                        child: Text('πŸ‡ͺπŸ‡Έ',
                            style: TextStyle(color: Colors.white)),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    ),
    ],
  );
}