Skip to content

Commit

Permalink
start service on back implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank-lol committed Feb 23, 2024
1 parent f5f6dc3 commit cd4e824
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 53 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ apply plugin: 'com.google.gms.google-services'

android {
namespace "com.example.anom_alert"
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 34
ndkVersion flutter.ndkVersion

compileOptions {
Expand Down
7 changes: 4 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

final notificationToken = await FirebaseMessaging.instance.getToken(vapidKey: "BOIgLBQCEnKa0V99S4gncnr_1mhgnS6aVKwV1AR_bWvSsESA8TR2_hHF4LESLfeirWoz8kt8RovfVPJTq7uxB_E");
print(notificationToken);
await FirebaseApi().initNotifications();
final token = await FirebaseMessaging.instance.getToken(vapidKey: "BOIgLBQCEnKa0V99S4gncnr_1mhgnS6aVKwV1AR_bWvSsESA8TR2_hHF4LESLfeirWoz8kt8RovfVPJTq7uxB_E");
print(token);


FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);


Expand Down
6 changes: 4 additions & 2 deletions lib/providers/recordings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class RecordingsNotifier extends StateNotifier<List<Recording>> {
print("no token");
return;
}

//print("$baseUrl/recording/get_recordings?id=${selectedCamera.id!}");
final response = await http.get(
Uri.parse("$baseUrl/recordings/get_recordings?id=${selectedCamera.id!}"),
Uri.parse("$baseUrl/recording/get_recordings?id=${selectedCamera.id!}"),

headers: {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token'
},
);
print(response.body);

if (response.statusCode == 200) {
List<Recording>finalRecordings = [];
Expand Down
23 changes: 12 additions & 11 deletions lib/screens/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ class _LoginScreenState extends State<LoginScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const BackButton(),
BackButton(),
Expanded(
child: SingleChildScrollView(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 36),
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 36),
child: Column(
children: [
Text(
Expand All @@ -141,10 +141,11 @@ class _LoginScreenState extends State<LoginScreen> {
TextField(
style: const TextStyle(color: Color(0xFF515D6B)),
controller: _emailController,
decoration: const InputDecoration(
label: Text("Email"),
hintText: "Enter your email",
),
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
label: Text("Email"),
hintText: "Enter your email",
hintStyle: GoogleFonts.inter(fontSize: 16)),
),
const SizedBox(
height: 16,
Expand All @@ -153,10 +154,10 @@ class _LoginScreenState extends State<LoginScreen> {
style: const TextStyle(color: Color(0xFF515D6B)),
obscureText: true,
controller: _passwordController,
decoration: const InputDecoration(
label: Text("Password"),
hintText: "Enter your Password",
),
decoration: InputDecoration(
label: Text("Password"),
hintText: "Enter your Password",
hintStyle: GoogleFonts.inter(fontSize: 16)),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
Expand Down
36 changes: 19 additions & 17 deletions lib/screens/auth/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ class _RegisterScreenState extends State<RegisterScreen> {
),
TextFormField(
style: const TextStyle(color: Color(0xFF515D6B)),
decoration: const InputDecoration(
label: Text("Name"),
hintText: "Enter your name",
),
keyboardType: TextInputType.name,
decoration: InputDecoration(
label: Text("Name"),
hintText: "Enter your name",
hintStyle: GoogleFonts.inter(fontSize: 16)),
validator: (value) {
if (value == null ||
value.isEmpty ||
Expand All @@ -135,11 +136,12 @@ class _RegisterScreenState extends State<RegisterScreen> {
height: 16,
),
TextFormField(
style: const TextStyle(color: Color(0xFF515D6B)),
decoration: const InputDecoration(
label: Text("Email"),
hintText: "Enter your email",
),
style: TextStyle(color: Color(0xFF515D6B)),
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
label: Text("Email"),
hintText: "Enter your email",
hintStyle: GoogleFonts.inter(fontSize: 16)),
validator: (value) {
if (value == null || value.isEmpty) {
return "Enter a valid Email ID";
Expand All @@ -156,10 +158,10 @@ class _RegisterScreenState extends State<RegisterScreen> {
TextFormField(
style: const TextStyle(color: Color(0xFF515D6B)),
obscureText: true,
decoration: const InputDecoration(
label: Text("Password"),
hintText: "Enter password",
),
decoration: InputDecoration(
label: Text("Password"),
hintText: "Enter password",
hintStyle: GoogleFonts.inter(fontSize: 16)),
validator: (value) {
if (value == null ||
value.isEmpty ||
Expand All @@ -178,10 +180,10 @@ class _RegisterScreenState extends State<RegisterScreen> {
TextFormField(
style: const TextStyle(color: Color(0xFF515D6B)),
obscureText: true,
decoration: const InputDecoration(
label: Text("Confirm Password"),
hintText: "Re-Enter password",
),
decoration: InputDecoration(
label: Text("Confirm Password"),
hintText: "Re-Enter password",
hintStyle: GoogleFonts.inter(fontSize: 16)),
validator: (value) {
if (_reEnteredPassword != _enteredPassword) {
return "Password does not match";
Expand Down
1 change: 1 addition & 0 deletions lib/screens/login_or_register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class LoginOrRegisterScreen extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
children: [
Expand Down
7 changes: 4 additions & 3 deletions lib/widgets/mjpeg_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MjpegPlayer extends HookWidget {
final String token;
@override
Widget build(BuildContext context) {
print("camara is running");
final isRunning = useState(true);
return Center(
child: Mjpeg(
Expand All @@ -17,9 +18,9 @@ class MjpegPlayer extends HookWidget {
print(stack);
return Text(error.toString(), style: TextStyle(color: Colors.red));
},
stream:
'http://uk.jokkmokk.jp/photo/nr4/latest.jpg',
// streamUrl,
stream: streamUrl ,
// 'http://uk.jokkmokk.jp/photo/nr4/latest.jpg',
// streamUrl,
headers: {
'Content-type': 'application/json',
'Accept': 'application/json',
Expand Down
61 changes: 47 additions & 14 deletions lib/widgets/new_camera.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import 'dart:convert';

import 'package:anom_alert/providers/camera_provider.dart';
import 'package:anom_alert/screens/camera_detail.dart';
import 'package:anom_alert/screens/home_page.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:firebase_messaging/firebase_messaging.dart';

import 'package:anom_alert/models/camera.dart';

class NewCamera extends StatelessWidget {
const NewCamera(this.camera, {required this.token,super.key});
const NewCamera(this.camera, {required this.token, super.key});

final Camera camera;
final String token;

@override
Widget build(BuildContext context) {
void onPressCamera() async{
final reply = await Navigator.of(context).push<String>(
MaterialPageRoute(builder: (ctx) => CameraDetailsScreen(camera, token: token,)));
if(reply=="delete"){
void onPressCamera() async {
final reply = await Navigator.of(context).push<String>(MaterialPageRoute(
builder: (ctx) => CameraDetailsScreen(
camera,
token: token,
)));
if (reply == "delete") {
print("delete");
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (ctx)=>HomePage(token: token,)));
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (ctx) => HomePage(
token: token,
)));
} else {
print("start");
final notificationToken = await FirebaseMessaging.instance.getToken(
vapidKey:
"BOIgLBQCEnKa0V99S4gncnr_1mhgnS6aVKwV1AR_bWvSsESA8TR2_hHF4LESLfeirWoz8kt8RovfVPJTq7uxB_E");
print(notificationToken);
Future.delayed(Duration(seconds: 5), () {
final response = http.post(Uri.parse("$baseUrl/user/start"),
headers: {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token'
},
body: jsonEncode(<String, String>{
'camera_id': camera.id!,
'device_token': notificationToken!
}));
});
}
}

return Padding(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: InkWell(
Expand Down Expand Up @@ -54,17 +84,20 @@ class NewCamera extends StatelessWidget {
? Text("Current Status : ON")
: Text("Current Status : OFF"),
Spacer(),
Text(
"Anomaly detected",
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Colors.yellow),
),
// Text(
// "Anomaly detected",
// style: Theme.of(context)
// .textTheme
// .bodyMedium!
// .copyWith(color: Colors.yellow),
// ),
],
),
const Spacer(),
Image.asset("assets/images/cctv-camera.png",height: 100,),
Image.asset(
"assets/images/cctv-camera.png",
height: 100,
),
],
),
),
Expand Down
14 changes: 12 additions & 2 deletions lib/widgets/recording_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:anom_alert/providers/recordings_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:anom_alert/models/camera.dart';
import 'package:url_launcher/url_launcher.dart';

class RecordingsItem extends ConsumerStatefulWidget {
RecordingsItem(this.camera, {super.key});
Expand All @@ -19,11 +20,18 @@ class _RecordingsItemState extends ConsumerState<RecordingsItem> {
void initState() {
// TODO: implement initState
super.initState();
super.initState();
//super.initState();
_recordingsFuture =
ref.read(recordingProvider.notifier).fetchRecordings(widget.camera);
}

_launchURL(String recordingUrl) async {
final Uri url = Uri.parse(recordingUrl);
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
}

@override
Widget build(BuildContext context) {
final allRecordings = ref.watch(recordingProvider);
Expand All @@ -39,9 +47,11 @@ class _RecordingsItemState extends ConsumerState<RecordingsItem> {
itemCount: allRecordings.length,
itemBuilder: (ctx, index) => ListTile(
leading: CircleAvatar(

radius: 24,
child: Icon(Icons.error_outline_rounded),
),
onTap: () {},
onTap:(){ _launchURL(allRecordings[index].video_url!);},
title: Text(
allRecordings[index].anomaly!,
//"Fighting"
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "generated_plugin_registrant.h"

#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import google_sign_in_ios
import path_provider_foundation
import shared_preferences_foundation
import sqflite
import url_launcher_macos
import video_player_avfoundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand All @@ -26,5 +27,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
}
Loading

0 comments on commit cd4e824

Please sign in to comment.