Advertisement
TitanOP

Rotating Dial

Dec 30th, 2023
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.14 KB | Source Code | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_svg/flutter_svg.dart';
  3. import 'dart:math' as math;
  4.  
  5. class Pawned extends StatefulWidget {
  6.   const Pawned({super.key});
  7.  
  8.   @override
  9.   State<Pawned> createState() => _PawnedState();
  10. }
  11.  
  12. class _PawnedState extends State<Pawned> {
  13.   double outerDialAngle = 0.0;
  14.  
  15.   @override
  16.   Widget build(BuildContext context) {
  17.     return Scaffold(
  18.       appBar: AppBar(
  19.         title: const Text('Combination Dial'),
  20.       ),
  21.       body: Center(
  22.         child: Stack(
  23.           alignment: Alignment.center,
  24.           children: [
  25.             // Outer Dial
  26.             GestureDetector(
  27.               onPanUpdate: (details) {
  28.                 setState(() {
  29.                   outerDialAngle += details.primaryDelta ?? 0.0;
  30.                 });
  31.               },
  32.               child: Transform.rotate(
  33.                 angle: math.pi * outerDialAngle / 180.0,
  34.                 child: SvgPicture.asset(
  35.                   'asset/outer_dial.svg', // Replace with your SVG image path
  36.                 ),
  37.               ),
  38.             ),
  39.  
  40.             // Progress Dial
  41.             SizedBox(
  42.               width: 282,
  43.               height: 282,
  44.               child: CircularProgressIndicator(
  45.                 value: outerDialAngle % 360 / 360,
  46.                 backgroundColor: Colors.grey,
  47.                 valueColor: const AlwaysStoppedAnimation<Color>(Colors.green),
  48.               ),
  49.             ),
  50.  
  51.             // Inner Circle
  52.             Container(
  53.               width: 192,
  54.               height: 192,
  55.               decoration: const BoxDecoration(
  56.                 shape: BoxShape.circle,
  57.                 color: Colors.green,
  58.               ),
  59.               child: Center(
  60.                 child: Text(
  61.                   calculateNumber(outerDialAngle),
  62.                   style: const TextStyle(fontSize: 24),
  63.                 ),
  64.               ),
  65.             ),
  66.           ],
  67.         ),
  68.       ),
  69.     );
  70.   }
  71.  
  72.   String calculateNumber(double angle) {
  73.     // Calculate the number based on the angle
  74.     int number = ((angle % 360) / 18).round() + 1;
  75.     return number.toString();
  76.   }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement