class LoginDropdown extends StatefulWidget {
final Function(String) onUserRoleChanged;
const LoginDropdown({
required this.onUserRoleChanged,
});
@override
State<LoginDropdown> createState() => _LoginDropdownState();
}
class _LoginDropdownState extends State<LoginDropdown> {
bool isShowMenu = false;
String currentRole = UserRole.mcOperator;
Color roleDropdownButtonColor = AppColors.gray_3;
@override
Widget build(
BuildContext context,
) =>
MouseRegion(
onEnter: (_) =>
setState(() => roleDropdownButtonColor = AppColors.gray_1),
onExit: (_) =>
setState(() => roleDropdownButtonColor = AppColors.gray_3),
child: GestureDetector(
onTap: () {
setState(() {
// ignore: avoid_bool_literals_in_conditional_expressions
isShowMenu = isShowMenu ? false : true;
});
},
child: Stack(
children: [
Container(
height: 56,
width: 418,
decoration: BoxDecoration(
color: roleDropdownButtonColor,
borderRadius: const BorderRadius.all(
Radius.circular(12),
),
),
child: Padding(
padding: const EdgeInsets.only(
left: 20,
right: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
currentRole,
style: AppFonsts.dropDown_1,
),
Image.asset(
'icons/dropdown_arrow.png',
height: 20,
width: 20,
),
],
),
),
),
if (isShowMenu)
Padding(
// 56 - is height of first container,
// 8 - is constraint between containers
padding: const EdgeInsets.only(top: 56 + 8),
child: Container(
height: 166,
width: 418,
decoration: const BoxDecoration(
boxShadow: [
// BoxShadow setup found here:
// https://devsheet.com/code-snippet/add-box-shadow-to-container-in-flutter/
BoxShadow(
color: AppColors.gray_6,
blurRadius: 90,
offset: Offset(0, 20),
)
],
color: AppColors.white,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 14),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (var role in UserRole.list)
LoginDropdownItem(
onTap: () {
setState(() {
isShowMenu = false;
currentRole = role;
widget.onUserRoleChanged(role);
});
},
userRole: role,
),
],
),
),
),
),
],
),
),
);
}
Есть встроенный typedef:
final ValueChanged<String> onUserRoleChanged;
Дальше не буду, но есть много над чем работать 🤓
Спасибо!
А если не секрет, почему дальше не будете? :) было бы полезно