VipulUthaiah099

Untitled

Nov 12th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:vibration/vibration.dart';
  3. import 'package:vibrator/vibrate.dart';
  4. import 'package:flutter/services.dart';
  5. import 'dart:async';
  6. void main() => runApp(VibratingApp());
  7.  
  8. class VibratingApp extends StatelessWidget {
  9.  
  10. format(Duration d) => d.toString().split('.').first.padLeft(8, "0");
  11. final d1 = Duration(hours: 17, minutes: 3);
  12. final d2 = Duration(hours: 9, minutes: 2, seconds: 26);
  13. final d3 = Duration(milliseconds: 0);
  14. String _printDuration(Duration duration) {
  15. String twoDigits(int n) => n.toString().padLeft(2, "0");
  16. String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
  17. String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
  18. return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
  19. }
  20. Timer daleay=Timer.periodic(Duration(seconds:1), (Timer t) => Vibration.vibrate(duration: 1000));
  21.  
  22. final dur = Duration(
  23. days: 5,
  24. hours: 23,
  25. minutes: 59,
  26. seconds: 59,
  27. milliseconds: 999,
  28. microseconds: 999,
  29. );
  30. @override
  31. Widget build(BuildContext context) {
  32. return MaterialApp(
  33. debugShowCheckedModeBanner: false,
  34. home: Scaffold(
  35. appBar: AppBar(
  36. title: const Text('Vibration Plugin example app'),
  37. ),
  38. body: Builder(
  39. builder: (BuildContext context) {
  40. return Center(
  41. child: Column(
  42. children: <Widget>[
  43. RaisedButton(
  44. child: Text('Vibrate for default 500ms'),
  45. onPressed: () {
  46. Vibration.vibrate(
  47. duration:1222
  48. );
  49. },
  50. ),
  51. RaisedButton(
  52. child: Text('Vibrate for 1000ms'),
  53. onPressed: () {
  54. HapticFeedback.lightImpact(
  55.  
  56. );
  57. // Vibration.vibrate(duration: 100 * 60 * 60, );
  58. // // Vibration.vibrate(duration: Duration.secondsPerMinute);
  59. // // Vibration.vibrate(duration:d1.inMinutes *100*60*600);
  60. // Vibration.vibrate(duration:dur.inMinutes );
  61. },
  62. ),
  63. RaisedButton(
  64. child: Text('Vibrate with pattern'),
  65. onPressed: () {
  66. final snackBar = SnackBar(
  67. content: Text(
  68. 'Pattern: wait 0.5s, vibrate 1s, wait 0.5s, vibrate 2s, wait 0.5s, vibrate 3s, wait 0.5s, vibrate 0.5s',
  69. ),
  70. );
  71. Scaffold.of(context).showSnackBar(snackBar);
  72. Vibration.vibrate(
  73.  
  74. pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500],
  75. );
  76. },
  77. ),
  78. RaisedButton(
  79. child: Text('Vibrate with pattern and amplitude'),
  80. onPressed: () {
  81. final snackBar = SnackBar(
  82. content: Text(
  83. 'Pattern: wait 0.5s, vibrate 1s, wait 0.5s, vibrate 2s, wait 0.5s, vibrate 3s, wait 0.5s, vibrate 0.5s',
  84. ),
  85. );
  86.  
  87. Scaffold.of(context).showSnackBar(snackBar);
  88. Vibration.vibrate(
  89. pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500],
  90. intensities: [128, 255, 64, 255],
  91. );
  92. },
  93. ),
  94. RaisedButton(
  95. child: Text('Vibrate with pattern and amplitude'),
  96. onPressed: () {
  97. Vibration.cancel();
  98. },
  99. ),
  100. RaisedButton(
  101. child: Text('Vibrate with pattern and amplitude'),
  102. onPressed: () {
  103. Navigator.push(
  104. context,
  105. MaterialPageRoute(builder: (context) => MainCard()),
  106. );
  107. },
  108. )
  109. ],
  110. ),
  111. );
  112. },
  113. ),
  114. ),
  115. );
  116. }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment