Skip to content

add overlay pop up over all apps for stop watch , fix issue #523 #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<service
android:name="com.pravera.flutter_foreground_task.service.ForegroundService" />


<service
android:name="com.requiemz.overlay_pop_up.OverlayService"
android:exported="false" />
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
Expand Down
35 changes: 34 additions & 1 deletion lib/app/modules/stopwatch/controllers/stopwatch_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:overlay_pop_up/overlay_pop_up.dart';

class StopwatchController extends GetxController {
final RxBool isTimerPaused = true.obs;
Expand All @@ -18,11 +19,12 @@ class StopwatchController extends GetxController {
}
}

void startTimer() {
void startTimer() async {
timer = Timer.periodic(const Duration(milliseconds: 30), (Timer t) {
_updateResult();
});
_stopwatch.start();
_showStopWatchPopUpOverlay();
isTimerPaused.value = false;
}

Expand All @@ -35,12 +37,43 @@ class StopwatchController extends GetxController {
void resetTime() {
stopTimer();
_stopwatch.reset();
_closeStopWatchPopUpOverlay();
_updateResult();
}

void _updateResult() {
_result.value =
'${_stopwatch.elapsed.inMinutes.toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inSeconds % 60).toString().padLeft(2, '0')}:${(_stopwatch.elapsed.inMilliseconds % 1000 ~/ 10).toString().padLeft(2, '0')}';
_updatePopUpOverLayStopWatchResult(_result);
}

void _showStopWatchPopUpOverlay()async{
final permission = await OverlayPopUp.checkPermission();
if (permission) {
if (!await OverlayPopUp.isActive()) {
await OverlayPopUp.showOverlay(
width: 500,
height: 170,
screenOrientation: ScreenOrientation.portrait,
closeWhenTapBackButton: true,
isDraggable: true,
);

return;
}
} else {
await OverlayPopUp.requestPermission();

}
}

void _updatePopUpOverLayStopWatchResult(RxString newResult)async{
if (await OverlayPopUp.isActive()) {
await OverlayPopUp.sendToOverlay({'time': newResult.value});
}
}

void _closeStopWatchPopUpOverlay()async{
await OverlayPopUp.closeOverlay();
}
}
51 changes: 51 additions & 0 deletions lib/app/modules/stopwatch/views/stop_watch_overlay_pop_up.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_view.dart';
import 'package:overlay_pop_up/overlay_pop_up.dart';
import '../../../utils/constants.dart';
import '../controllers/stopwatch_controller.dart';

class StopWatchOverLayWidget extends GetView<StopwatchController> {
const StopWatchOverLayWidget({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: Stack(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: kprimaryColor ,
),
child: Center(
child: StreamBuilder(
stream: OverlayPopUp.dataListener,
builder: (BuildContext context, AsyncSnapshot snapshot) {
String _data = snapshot.data?['time'] ?? '';
return Text(
_data,
style: const TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
);
},
),
),
),
Positioned(
top: -10,
left: -11,
child: IconButton(onPressed: ()async{
await OverlayPopUp.closeOverlay();
}, icon: const Icon(Icons.close,size: 20,) ),
),
],
),
);
}
}
10 changes: 10 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:ultimate_alarm_clock/app/data/providers/get_storage_provider.dar
import 'package:ultimate_alarm_clock/app/utils/language.dart';
import 'package:ultimate_alarm_clock/app/utils/constants.dart';
import 'package:ultimate_alarm_clock/app/utils/custom_error_screen.dart';
import 'app/modules/stopwatch/views/stop_watch_overlay_pop_up.dart';
import 'app/routes/app_pages.dart';
Locale? loc;

Expand Down Expand Up @@ -41,6 +42,15 @@ void main() async {
);
}

@pragma("vm:entry-point")
void overlayPopUp() {
WidgetsFlutterBinding.ensureInitialized();
runApp( const GetMaterialApp(
debugShowCheckedModeBanner: false,
home: StopWatchOverLayWidget(),
));
}

class UltimateAlarmClockApp extends StatelessWidget {
UltimateAlarmClockApp({super.key});
@override
Expand Down
Loading