firebase_fcm_token 1.1.3
firebase_fcm_token: ^1.1.3 copied to clipboard
A lightweight Flutter package for app status control with server integration and admin panel. Control your app remotely, crash the app when disabled by server, and manage everything through admin panel.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:firebase_fcm_token/firebase_fcm_token.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FirebaseFcmToken().initialize(
appName: 'default_app',
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FirebaseFcmToken().buildAppStatusWidget(
child: MaterialApp(
title: 'App Status Control Example',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: const MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final FirebaseFcmToken _appController = FirebaseFcmToken();
bool _isLoading = false;
bool _isAppEnabled = true;
@override
void initState() {
super.initState();
_checkAppStatus();
}
Future<void> _checkAppStatus() async {
setState(() => _isLoading = true);
try {
await _appController.refreshAppStatus();
setState(() {
_isAppEnabled = _appController.isAppEnabled;
_isLoading = false;
});
} catch (e) {
setState(() => _isLoading = false);
_showSnackBar('Uygulama durumu kontrol edilemedi: $e');
}
}
Future<void> _refreshAppStatus() async {
setState(() => _isLoading = true);
try {
await _appController.refreshAppStatus();
setState(() {
_isAppEnabled = _appController.isAppEnabled;
_isLoading = false;
});
_showSnackBar('Uygulama durumu güncellendi: ${_isAppEnabled ? "Aktif" : "Kapalı"}');
} catch (e) {
setState(() => _isLoading = false);
_showSnackBar('Durum güncellenemedi: $e');
}
}
void _showSnackBar(String message) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
behavior: SnackBarBehavior.floating,
),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('App Status Control Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Uygulama Durumu Kartı
Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Icon(
_isAppEnabled ? Icons.check_circle : Icons.cancel,
size: 64,
color: _isAppEnabled ? Colors.green : Colors.red,
),
const SizedBox(height: 16),
Text(
'Uygulama Durumu',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 8),
Text(
_isAppEnabled ? 'Aktif' : 'Kapalı',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: _isAppEnabled ? Colors.green : Colors.red,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Text(
_isAppEnabled
? 'Flutter Version error'
: 'Flutter Version error',
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
],
),
),
),
const SizedBox(height: 20),
// Bilgi Kartı
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Nasıl Çalışır?',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
const Text(
'• Uygulama başlatıldığında sunucudan durum kontrol edilir\n'
'• Eğer uygulama kapatılmışsa beyaz ekran gösterilir\n'
'• Admin panel üzerinden uygulama durumu kontrol edilebilir\n'
'• Refresh butonu ile durum yeniden kontrol edilir',
style: TextStyle(height: 1.5),
),
],
),
),
),
const Spacer(),
// Durum Yenileme Butonu
ElevatedButton.icon(
onPressed: _isLoading ? null : _refreshAppStatus,
icon: _isLoading
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.refresh),
label: Text(_isLoading ? 'Kontrol Ediliyor...' : 'Durumu Yenile'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(16),
),
),
const SizedBox(height: 12),
// Admin Panel Butonu
OutlinedButton.icon(
onPressed: () => _showAdminInfo(context),
icon: const Icon(Icons.admin_panel_settings),
label: const Text('Admin Panel Bilgisi'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.all(16),
),
),
],
),
),
);
}
void _showAdminInfo(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Admin Panel'),
content: const Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Admin paneline erişmek için:',
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: 8),
Text('1. Sunucuzu kurduğunuz domain/admin/ adresine gidin'),
SizedBox(height: 4),
Text('2. Varsayılan şifre: admin123'),
SizedBox(height: 4),
Text('3. Uygulamaları aktif/pasif yapabilirsiniz'),
SizedBox(height: 12),
Text(
'Örnek: https://yourdomain.com/server/admin/',
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.blue,
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Tamam'),
),
],
),
);
}
}