ModernMemoires/lib/views/first_page/widgets/drag_widget.dart

92 lines
2.7 KiB
Dart
Raw Normal View History

2023-12-17 23:00:31 +01:00
import 'package:flutter/material.dart';
2024-01-09 12:34:44 +01:00
import '../../../utils/circle_painter.dart';
2023-12-25 14:10:31 +01:00
2023-12-17 23:00:31 +01:00
class DragWidget extends StatefulWidget {
2024-01-09 12:34:44 +01:00
const DragWidget({super.key});
2023-12-17 23:00:31 +01:00
@override
2024-01-09 12:34:44 +01:00
State<DragWidget> createState() => _DragWidget();
2023-12-17 23:00:31 +01:00
}
2024-01-09 12:34:44 +01:00
class _DragWidget extends State<DragWidget> {
2023-12-17 23:00:31 +01:00
double _sliderValue = 0.0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
2023-12-25 14:10:31 +01:00
fit: StackFit.expand,
2023-12-17 23:00:31 +01:00
children: [
Positioned.fill(
child: CustomPaint(
2024-01-01 18:31:10 +01:00
painter: CirclePainter(_sliderValue, Colors.red),
2023-12-17 23:00:31 +01:00
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 20.0, left: 20.0),
child: Text(
"${DateTime.now().toLocal()}",
2024-01-09 12:34:44 +01:00
style: const TextStyle(fontSize: 18),
2023-12-17 23:00:31 +01:00
),
),
const Padding(
padding: EdgeInsets.only(left: 20.0),
child: Text(
"How are you today?",
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
),
2024-01-09 12:34:44 +01:00
const SizedBox(height: 32), // 2 line padding
2023-12-17 23:00:31 +01:00
SliderTheme(
data: SliderTheme.of(context).copyWith(
trackShape: CustomTrackShape(),
thumbShape: SliderComponentShape.noThumb,
),
child: Slider(
min: 0.0,
max: 100.0,
value: _sliderValue,
onChanged: (value) {
setState(() {
_sliderValue = value;
});
},
),
),
if (_sliderValue > 0)
Padding(
2024-01-09 12:34:44 +01:00
padding: const EdgeInsets.only(left: 20.0),
2023-12-17 23:00:31 +01:00
child: Text(
"${_sliderValue.toStringAsFixed(0)}%",
2024-01-09 12:34:44 +01:00
style: const TextStyle(fontSize: 18),
2023-12-17 23:00:31 +01:00
),
),
],
),
],
),
);
}
}
class CustomTrackShape extends RoundedRectSliderTrackShape {
@override
Rect getPreferredRect({
required RenderBox parentBox,
Offset offset = Offset.zero,
required SliderThemeData sliderTheme,
bool isEnabled = false,
bool isDiscrete = false,
}) {
final double trackHeight = sliderTheme.trackHeight ?? 4;
final double trackLeft = offset.dx;
2024-01-09 12:34:44 +01:00
final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2;
2023-12-17 23:00:31 +01:00
final double trackWidth = parentBox.size.width;
return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
}
}