selectProfileModal static method

Future<void> selectProfileModal({
  1. required BuildContext context,
  2. required List<AppProfile> profiles,
  3. required String currentProfileId,
  4. required Future<void> onChangeProfile(
    1. AppProfile
    ),
  5. required void onCreateProfile(),
})

Implementation

static Future<void> selectProfileModal({
  required BuildContext context, required List<AppProfile> profiles,
  required String currentProfileId, required Future<void> Function(AppProfile) onChangeProfile,
  required void Function() onCreateProfile,}) async {

  try {
    UserService userServiceImpl = Get.find<UserService>();
    await userServiceImpl.getProfiles();
    await showModalBottomSheet(
        elevation: 0,
        backgroundColor: AppTheme.canvasColor25(context),
        context: context,
        builder: (BuildContext context) {
          return SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  Container(
                    padding: const EdgeInsets.only(top: 10),
                    margin: const EdgeInsets.symmetric(horizontal: 15),
                    decoration: BoxDecoration(
                        color: AppColor.main95,
                        borderRadius: const BorderRadius.only(topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0))
                    ),
                    child: ListView.separated(
                        padding: EdgeInsets.zero,
                        shrinkWrap: true,
                        separatorBuilder:  (context, index) => const Divider(),
                        itemCount: userServiceImpl.user.profiles.length,
                        itemBuilder: (ctx, index) {
                          AppProfile profile = userServiceImpl.user.profiles.elementAt(index);
                          return ListTile(
                            leading: IconButton(
                              icon: CircleAvatar(
                                  maxRadius: 60,
                                  backgroundImage: CachedNetworkImageProvider(
                                      profile.photoUrl.isNotEmpty
                                          ? profile.photoUrl
                                          : AppProperties.getNoImageUrl()
                                  )
                              ),
                              onPressed: () async {
                                Navigator.pop(context);
                                if(currentProfileId != profile.id) {
                                  Navigator.pop(context);
                                  await userServiceImpl.changeProfile(profile);
                                }
                              },
                            ),
                            trailing: Icon(currentProfileId == profile.id
                                ? FontAwesomeIcons.circleDot : Icons.circle_outlined,
                                size: 30
                            ),
                            title: Text(profile.name,
                              style: const TextStyle(fontSize: 18),
                            ),
                            subtitle: Text("${profile.type.name.tr.capitalize} - ${profile.mainFeature.tr.capitalize}"),
                            onTap: () async {
                              Navigator.pop(context);
                              if(currentProfileId != profile.id) {
                                Navigator.pop(context);
                                await userServiceImpl.changeProfile(profile);
                              }
                            },
                          );
                        }
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.symmetric(horizontal: 15),
                    color: AppColor.main95,
                    child: ListTile(
                      leading: Container(
                        decoration: BoxDecoration(
                          borderRadius: const BorderRadius.all(Radius.circular(30)),
                          color: Colors.teal[100],
                        ),
                        child: const Icon(Icons.add, color: Colors.white),
                      ),
                      trailing: const Icon(Icons.arrow_forward_ios, size: 15,),
                      title: const Text("Crear perfil adicional",
                        style: TextStyle(color: Colors.white, fontSize: 15),
                      ),
                      subtitle: const Text("Agrega un perfil adicional para manejar distintas cuentas."),
                      onTap: () {
                        Navigator.pop(context);
                        Get.toNamed(AppRouteConstants.introProfile);
                      },
                    ),
                  ),
                ],
              ));
        });
  } catch(e) {
    AppConfig.logger.e(e.toString());
  }
}