radius_picker_widget.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import "package:flutter/material.dart";
  2. import "package:photos/core/constants.dart";
  3. import "package:photos/states/add_location_state.dart";
  4. import "package:photos/theme/colors.dart";
  5. import "package:photos/theme/ente_theme.dart";
  6. class CustomTrackShape extends RoundedRectSliderTrackShape {
  7. @override
  8. Rect getPreferredRect({
  9. required RenderBox parentBox,
  10. Offset offset = Offset.zero,
  11. required SliderThemeData sliderTheme,
  12. bool isEnabled = false,
  13. bool isDiscrete = false,
  14. }) {
  15. const trackHeight = 2.0;
  16. final trackWidth = parentBox.size.width;
  17. return Rect.fromLTWH(0, 0, trackWidth, trackHeight);
  18. }
  19. }
  20. class RadiusPickerWidget extends StatefulWidget {
  21. final ValueNotifier<int?> memoriesCountNotifier;
  22. const RadiusPickerWidget(this.memoriesCountNotifier, {super.key});
  23. @override
  24. State<RadiusPickerWidget> createState() => _RadiusPickerWidgetState();
  25. }
  26. class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
  27. double selectedIndex = defaultRadiusValueIndex.toDouble();
  28. @override
  29. Widget build(BuildContext context) {
  30. final textTheme = getEnteTextTheme(context);
  31. final colorScheme = getEnteColorScheme(context);
  32. return Row(
  33. children: [
  34. Container(
  35. height: 48,
  36. width: 48,
  37. decoration: BoxDecoration(
  38. color: colorScheme.fillFaint,
  39. borderRadius: const BorderRadius.all(Radius.circular(2)),
  40. ),
  41. padding: const EdgeInsets.all(4),
  42. child: Column(
  43. mainAxisSize: MainAxisSize.min,
  44. mainAxisAlignment: MainAxisAlignment.center,
  45. crossAxisAlignment: CrossAxisAlignment.center,
  46. children: [
  47. Expanded(
  48. flex: 6,
  49. child: Text(
  50. _selectedRadius(context).toInt().toString(),
  51. style: _selectedRadius(context) != 1200
  52. ? textTheme.largeBold
  53. : textTheme.bodyBold,
  54. textAlign: TextAlign.center,
  55. ),
  56. ),
  57. Expanded(
  58. flex: 5,
  59. child: Text(
  60. "km",
  61. style: textTheme.miniMuted,
  62. ),
  63. ),
  64. ],
  65. ),
  66. ),
  67. const SizedBox(width: 4),
  68. Expanded(
  69. child: Padding(
  70. padding: const EdgeInsets.symmetric(horizontal: 8),
  71. child: Column(
  72. crossAxisAlignment: CrossAxisAlignment.start,
  73. mainAxisSize: MainAxisSize.min,
  74. children: [
  75. Text("Radius", style: textTheme.body),
  76. const SizedBox(height: 10),
  77. SizedBox(
  78. height: 12,
  79. child: SliderTheme(
  80. data: SliderThemeData(
  81. overlayColor: Colors.transparent,
  82. thumbColor: strokeSolidMutedLight,
  83. activeTrackColor: strokeSolidMutedLight,
  84. inactiveTrackColor: colorScheme.strokeFaint,
  85. activeTickMarkColor: colorScheme.strokeMuted,
  86. inactiveTickMarkColor: strokeSolidMutedLight,
  87. trackShape: CustomTrackShape(),
  88. thumbShape: const RoundSliderThumbShape(
  89. enabledThumbRadius: 6,
  90. pressedElevation: 0,
  91. elevation: 0,
  92. ),
  93. tickMarkShape: const RoundSliderTickMarkShape(
  94. tickMarkRadius: 1,
  95. ),
  96. ),
  97. child: RepaintBoundary(
  98. child: Slider(
  99. value: selectedIndex,
  100. onChanged: (value) {
  101. setState(() {
  102. selectedIndex = value;
  103. });
  104. InheritedLocationTagData.of(
  105. context,
  106. ).updateSelectedIndex(
  107. value.toInt(),
  108. );
  109. widget.memoriesCountNotifier.value = null;
  110. },
  111. min: 0,
  112. max: radiusValues.length - 1,
  113. divisions: radiusValues.length - 1,
  114. ),
  115. ),
  116. ),
  117. ),
  118. ],
  119. ),
  120. ),
  121. ),
  122. ],
  123. );
  124. }
  125. double _selectedRadius(BuildContext context) {
  126. return radiusValues[
  127. InheritedLocationTagData.of(context).selectedRadiusIndex];
  128. }
  129. }