feat: initialize new Flutter project with core feature structure and cross-platform configuration
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppColors {
|
||||
static const Color background = Color(0xFF0A0E14);
|
||||
static const Color surface = Color(0xFF161B22);
|
||||
static const Color primary = Color(0xFF2D7DEB); // Electric Blue
|
||||
static const Color secondary = Color(0xFF0F9D58); // Emerald Green
|
||||
static const Color accent = Color(0xFFF4B400); // Yellow
|
||||
static const Color error = Color(0xFFDB4437); // Red
|
||||
|
||||
static const Color textPrimary = Colors.white;
|
||||
static const Color textSecondary = Color(0xFF8B949E);
|
||||
|
||||
static const LinearGradient primaryGradient = LinearGradient(
|
||||
colors: [primary, Color(0xFF1A5FBC)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
);
|
||||
|
||||
static const LinearGradient backgroundGradient = LinearGradient(
|
||||
colors: [background, Color(0xFF10141B)],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'app_colors.dart';
|
||||
|
||||
class AppTheme {
|
||||
static ThemeData get darkTheme {
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: Brightness.dark,
|
||||
scaffoldBackgroundColor: AppColors.background,
|
||||
colorScheme: ColorScheme.dark(
|
||||
primary: AppColors.primary,
|
||||
secondary: AppColors.secondary,
|
||||
surface: AppColors.surface,
|
||||
error: AppColors.error,
|
||||
),
|
||||
textTheme: GoogleFonts.outfitTextTheme(
|
||||
const TextTheme(
|
||||
displayLarge: TextStyle(color: AppColors.textPrimary, fontWeight: FontWeight.bold),
|
||||
displayMedium: TextStyle(color: AppColors.textPrimary, fontWeight: FontWeight.bold),
|
||||
titleLarge: TextStyle(color: AppColors.textPrimary, fontWeight: FontWeight.w600),
|
||||
bodyLarge: TextStyle(color: AppColors.textPrimary),
|
||||
bodyMedium: TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
color: AppColors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
side: BorderSide(color: Colors.white.withOpacity(0.05)),
|
||||
),
|
||||
),
|
||||
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 56),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'dart:async';
|
||||
import 'package:nsd/nsd.dart';
|
||||
|
||||
abstract class IDiscoveryService {
|
||||
Future<void> registerService(int port);
|
||||
Future<void> stopRegistration();
|
||||
Stream<List<Service>> discoverServices();
|
||||
}
|
||||
|
||||
class DiscoveryService implements IDiscoveryService {
|
||||
Registration? _registration;
|
||||
final String _serviceType = '_http._tcp';
|
||||
final String _serviceName = 'FastWatcher';
|
||||
|
||||
@override
|
||||
Future<void> registerService(int port) async {
|
||||
_registration = await register(
|
||||
Service(
|
||||
name: _serviceName,
|
||||
type: _serviceType,
|
||||
port: port,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stopRegistration() async {
|
||||
if (_registration != null) {
|
||||
await unregister(_registration!);
|
||||
_registration = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<Service>> discoverServices() async* {
|
||||
final discovery = await startDiscovery(_serviceType);
|
||||
final controller = StreamController<List<Service>>();
|
||||
|
||||
void update() {
|
||||
controller.add(discovery.services);
|
||||
}
|
||||
|
||||
discovery.addListener(update);
|
||||
|
||||
yield* controller.stream;
|
||||
|
||||
// Note: In a real app, handle disposal
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:nsd/nsd.dart';
|
||||
import '../../data/services/discovery_service.dart';
|
||||
|
||||
|
||||
final discoveryServiceProvider = Provider((ref) => DiscoveryService());
|
||||
|
||||
final discoveredDevicesProvider = StreamProvider<List<Service>>((ref) {
|
||||
final service = ref.watch(discoveryServiceProvider);
|
||||
return service.discoverServices();
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf/shelf_io.dart' as io;
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
|
||||
class ReceiverServer {
|
||||
HttpServer? _server;
|
||||
final Function(Map<String, dynamic>) onPlayRequest;
|
||||
|
||||
ReceiverServer({required this.onPlayRequest});
|
||||
|
||||
Future<int> start() async {
|
||||
final router = Router();
|
||||
|
||||
router.post('/play', (Request request) async {
|
||||
final payload = await request.readAsString();
|
||||
try {
|
||||
final data = jsonDecode(payload) as Map<String, dynamic>;
|
||||
onPlayRequest(data);
|
||||
return Response.ok(jsonEncode({'status': 'success'}));
|
||||
} catch (e) {
|
||||
return Response.badRequest(body: jsonEncode({'error': 'Invalid JSON'}));
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/health', (Request request) {
|
||||
return Response.ok(jsonEncode({'status': 'ok'}));
|
||||
});
|
||||
|
||||
_server = await io.serve(router, InternetAddress.anyIPv4, 0); // Port 0 for auto-assign or fixed port
|
||||
print('Receiver Server running on port ${_server!.port}');
|
||||
return _server!.port;
|
||||
}
|
||||
|
||||
Future<void> stop() async {
|
||||
await _server?.close();
|
||||
_server = null;
|
||||
}
|
||||
|
||||
String? get ipAddress {
|
||||
// Note: This is a simplified way to get local IP.
|
||||
// In a real app, you might want to filter for the Wi-Fi interface.
|
||||
return 'Local IP';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../data/services/receiver_server.dart';
|
||||
import '../../../discovery/data/services/discovery_service.dart';
|
||||
|
||||
class ReceiverState {
|
||||
final bool isRunning;
|
||||
final int? port;
|
||||
final String? ipAddress;
|
||||
final Map<String, dynamic>? currentVideo;
|
||||
|
||||
ReceiverState({
|
||||
this.isRunning = false,
|
||||
this.port,
|
||||
this.ipAddress,
|
||||
this.currentVideo,
|
||||
});
|
||||
|
||||
ReceiverState copyWith({
|
||||
bool? isRunning,
|
||||
int? port,
|
||||
String? ipAddress,
|
||||
Map<String, dynamic>? currentVideo,
|
||||
}) {
|
||||
return ReceiverState(
|
||||
isRunning: isRunning ?? this.isRunning,
|
||||
port: port ?? this.port,
|
||||
ipAddress: ipAddress ?? this.ipAddress,
|
||||
currentVideo: currentVideo ?? this.currentVideo,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final receiverProvider = NotifierProvider<ReceiverNotifier, ReceiverState>(() {
|
||||
return ReceiverNotifier();
|
||||
});
|
||||
|
||||
class ReceiverNotifier extends Notifier<ReceiverState> {
|
||||
late ReceiverServer _server;
|
||||
final _discoveryService = DiscoveryService();
|
||||
|
||||
@override
|
||||
ReceiverState build() {
|
||||
_server = ReceiverServer(onPlayRequest: _handlePlayRequest);
|
||||
return ReceiverState();
|
||||
}
|
||||
|
||||
Future<void> startServer() async {
|
||||
if (state.isRunning) return;
|
||||
|
||||
final port = await _server.start();
|
||||
await _discoveryService.registerService(port);
|
||||
|
||||
state = state.copyWith(
|
||||
isRunning: true,
|
||||
port: port,
|
||||
// In a real app, use network_info_plus to get the real IP
|
||||
ipAddress: 'Checking...',
|
||||
);
|
||||
}
|
||||
|
||||
void _handlePlayRequest(Map<String, dynamic> data) {
|
||||
state = state.copyWith(currentVideo: data);
|
||||
}
|
||||
|
||||
Future<void> stopServer() async {
|
||||
await _server.stop();
|
||||
await _discoveryService.stopRegistration();
|
||||
state = ReceiverState();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../providers/receiver_providers.dart';
|
||||
import 'tv_player_screen.dart';
|
||||
|
||||
|
||||
class TVHomeScreen extends ConsumerStatefulWidget {
|
||||
const TVHomeScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<TVHomeScreen> createState() => _TVHomeScreenState();
|
||||
}
|
||||
|
||||
class _TVHomeScreenState extends ConsumerState<TVHomeScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Start the server as soon as the TV home opens
|
||||
Future.microtask(() => ref.read(receiverProvider.notifier).startServer());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final receiverState = ref.watch(receiverProvider);
|
||||
|
||||
ref.listen(receiverProvider, (previous, next) {
|
||||
final video = next.currentVideo;
|
||||
if (video != null) {
|
||||
final url = video['url'] as String;
|
||||
final title = video['title'] as String?;
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TVPlayerScreen(url: url, title: title),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
|
||||
body: Container(
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: AppColors.backgroundGradient,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Spacer(),
|
||||
// Glowing Logo Animation Placeholder
|
||||
TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0.8, end: 1.0),
|
||||
duration: const Duration(seconds: 2),
|
||||
curve: Curves.easeInOut,
|
||||
builder: (context, value, child) {
|
||||
return Transform.scale(
|
||||
scale: value,
|
||||
child: Opacity(
|
||||
opacity: 0.5 + (value - 0.8) * 2.5,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
onEnd: () {}, // Could loop it
|
||||
child: SvgPicture.asset(
|
||||
'assets/logo/fastwatcher-logo.svg',
|
||||
height: 180,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
Text(
|
||||
'Waiting for connection...',
|
||||
style: Theme.of(context).textTheme.displaySmall?.copyWith(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
fontWeight: FontWeight.w300,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Open FastWatcher on your phone to start casting',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// Connection Info Footer
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(48.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_InfoItem(
|
||||
label: 'DEVICE NAME',
|
||||
value: 'FastWatcher TV',
|
||||
),
|
||||
if (receiverState.isRunning)
|
||||
_InfoItem(
|
||||
label: 'SERVER PORT',
|
||||
value: '${receiverState.port}',
|
||||
),
|
||||
_InfoItem(
|
||||
label: 'IP ADDRESS',
|
||||
value: receiverState.ipAddress ?? 'Detecting...',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoItem extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
const _InfoItem({required this.label, required this.value});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: AppColors.primary,
|
||||
letterSpacing: 2,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:media_kit_video/media_kit_video.dart';
|
||||
|
||||
class TVPlayerScreen extends StatefulWidget {
|
||||
final String url;
|
||||
final String? title;
|
||||
|
||||
const TVPlayerScreen({super.key, required this.url, this.title});
|
||||
|
||||
@override
|
||||
State<TVPlayerScreen> createState() => _TVPlayerScreenState();
|
||||
}
|
||||
|
||||
class _TVPlayerScreenState extends State<TVPlayerScreen> {
|
||||
late final player = Player();
|
||||
late final controller = VideoController(player);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
player.open(Media(widget.url));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
player.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
children: [
|
||||
Video(controller: controller),
|
||||
if (widget.title != null)
|
||||
Positioned(
|
||||
top: 40,
|
||||
left: 40,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
widget.title!,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 24),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
||||
abstract class ILinkExtractionService {
|
||||
Future<String?> extractVideoUrl(String pageUrl);
|
||||
}
|
||||
|
||||
class LinkExtractionService implements ILinkExtractionService {
|
||||
HeadlessInAppWebView? _headlessWebView;
|
||||
|
||||
@override
|
||||
Future<String?> extractVideoUrl(String pageUrl) async {
|
||||
// 1. Check if it's already a video link
|
||||
if (_isVideoUrl(pageUrl)) return pageUrl;
|
||||
|
||||
// 2. Use Headless WebView to find the video
|
||||
String? foundUrl;
|
||||
|
||||
_headlessWebView = HeadlessInAppWebView(
|
||||
initialUrlRequest: URLRequest(url: WebUri(pageUrl)),
|
||||
onLoadResource: (controller, resource) {
|
||||
final url = resource.url.toString();
|
||||
if (_isVideoUrl(url)) {
|
||||
foundUrl = url;
|
||||
_headlessWebView?.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
await _headlessWebView?.run();
|
||||
|
||||
// Wait for some time to catch resources
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
|
||||
return foundUrl;
|
||||
}
|
||||
|
||||
bool _isVideoUrl(String url) {
|
||||
final lower = url.toLowerCase();
|
||||
return lower.contains('.m3u8') ||
|
||||
lower.contains('.mp4') ||
|
||||
lower.contains('.mkv');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:nsd/nsd.dart';
|
||||
import '../../data/services/link_extraction_service.dart';
|
||||
|
||||
|
||||
class SenderState {
|
||||
final Service? connectedDevice;
|
||||
final bool isExtracting;
|
||||
final bool isSending;
|
||||
final List<String> history;
|
||||
|
||||
SenderState({
|
||||
this.connectedDevice,
|
||||
this.isExtracting = false,
|
||||
this.isSending = false,
|
||||
this.history = const [],
|
||||
});
|
||||
|
||||
SenderState copyWith({
|
||||
Service? connectedDevice,
|
||||
bool? isExtracting,
|
||||
bool? isSending,
|
||||
List<String>? history,
|
||||
}) {
|
||||
return SenderState(
|
||||
connectedDevice: connectedDevice ?? this.connectedDevice,
|
||||
isExtracting: isExtracting ?? this.isExtracting,
|
||||
isSending: isSending ?? this.isSending,
|
||||
history: history ?? this.history,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final senderProvider = NotifierProvider<SenderNotifier, SenderState>(() {
|
||||
return SenderNotifier();
|
||||
});
|
||||
|
||||
class SenderNotifier extends Notifier<SenderState> {
|
||||
final _dio = Dio();
|
||||
final _linkExtractionService = LinkExtractionService();
|
||||
|
||||
@override
|
||||
SenderState build() => SenderState();
|
||||
|
||||
void connectToDevice(Service device) {
|
||||
state = state.copyWith(connectedDevice: device);
|
||||
}
|
||||
|
||||
Future<void> sendLink(String url) async {
|
||||
if (state.connectedDevice == null) return;
|
||||
|
||||
state = state.copyWith(isExtracting: true);
|
||||
|
||||
final videoUrl = await _linkExtractionService.extractVideoUrl(url);
|
||||
|
||||
if (videoUrl == null) {
|
||||
state = state.copyWith(isExtracting: false);
|
||||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(isExtracting: false, isSending: true);
|
||||
|
||||
try {
|
||||
final device = state.connectedDevice!;
|
||||
final endpoint = 'http://${device.host}:${device.port}/play';
|
||||
|
||||
await _dio.post(endpoint, data: {
|
||||
'url': videoUrl,
|
||||
'title': 'Shared Video',
|
||||
'timestamp': DateTime.now().millisecondsSinceEpoch,
|
||||
});
|
||||
|
||||
state = state.copyWith(
|
||||
isSending: false,
|
||||
history: [url, ...state.history],
|
||||
);
|
||||
} catch (e) {
|
||||
state = state.copyWith(isSending: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../../../discovery/presentation/providers/discovery_providers.dart';
|
||||
import '../providers/sender_providers.dart';
|
||||
|
||||
class MobileSenderScreen extends ConsumerStatefulWidget {
|
||||
const MobileSenderScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<MobileSenderScreen> createState() => _MobileSenderScreenState();
|
||||
}
|
||||
|
||||
class _MobileSenderScreenState extends ConsumerState<MobileSenderScreen> {
|
||||
final _urlController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_urlController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final devicesAsync = ref.watch(discoveredDevicesProvider);
|
||||
final senderState = ref.watch(senderProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('FastWatcher'),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
if (senderState.connectedDevice != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.cast_connected, color: AppColors.primary),
|
||||
onPressed: () {
|
||||
// TODO: Show connection info or disconnect
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: AppColors.backgroundGradient,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (senderState.connectedDevice == null) ...[
|
||||
Text(
|
||||
'Cast to TV',
|
||||
style: Theme.of(context).textTheme.displaySmall,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Select a TV on your network to begin',
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Expanded(
|
||||
child: _buildDiscoveryList(devicesAsync),
|
||||
),
|
||||
] else ...[
|
||||
_buildLinkInput(senderState),
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
'History',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: _buildHistoryList(senderState),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDiscoveryList(AsyncValue devicesAsync) {
|
||||
return devicesAsync.when(
|
||||
data: (devices) {
|
||||
if (devices.isEmpty) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 20),
|
||||
Text('Searching for TVs...'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: (devices as List).length,
|
||||
itemBuilder: (context, index) {
|
||||
final device = devices[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: ListTile(
|
||||
leading: const CircleAvatar(
|
||||
backgroundColor: AppColors.primary,
|
||||
child: Icon(Icons.tv_rounded, color: Colors.white),
|
||||
),
|
||||
title: Text(device.name ?? 'Unknown TV'),
|
||||
subtitle: Text('${device.host}:${device.port}'),
|
||||
trailing: const Icon(Icons.cast),
|
||||
onTap: () {
|
||||
ref.read(senderProvider.notifier).connectToDevice(device);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (err, stack) => Center(child: Text('Error: $err')),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLinkInput(SenderState state) {
|
||||
return Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: _urlController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Paste video link here...',
|
||||
filled: true,
|
||||
fillColor: AppColors.surface,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
suffixIcon: state.isExtracting || state.isSending
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.send_rounded, color: AppColors.primary),
|
||||
onPressed: () {
|
||||
if (_urlController.text.isNotEmpty) {
|
||||
ref.read(senderProvider.notifier).sendLink(_urlController.text);
|
||||
_urlController.clear();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (state.isExtracting)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 8.0),
|
||||
child: Text('Extracting video link...', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHistoryList(SenderState state) {
|
||||
if (state.history.isEmpty) {
|
||||
return const Center(child: Text('No history yet'));
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: state.history.length,
|
||||
itemBuilder: (context, index) {
|
||||
final url = state.history[index];
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.history_rounded, size: 20),
|
||||
title: Text(url, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
onTap: () => _urlController.text = url,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
enum DeviceRole { phone, tv, unknown }
|
||||
|
||||
class SetupRepository {
|
||||
static const String _roleKey = 'device_role';
|
||||
|
||||
Future<void> setRole(DeviceRole role) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_roleKey, role.name);
|
||||
}
|
||||
|
||||
Future<DeviceRole> getRole() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final roleName = prefs.getString(_roleKey);
|
||||
if (roleName == null) return DeviceRole.unknown;
|
||||
return DeviceRole.values.firstWhere(
|
||||
(e) => e.name == roleName,
|
||||
orElse: () => DeviceRole.unknown,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../data/repositories/setup_repository.dart';
|
||||
|
||||
final setupRepositoryProvider = Provider((ref) => SetupRepository());
|
||||
|
||||
final deviceRoleProvider = NotifierProvider<DeviceRoleNotifier, DeviceRole>(() {
|
||||
return DeviceRoleNotifier();
|
||||
});
|
||||
|
||||
class DeviceRoleNotifier extends Notifier<DeviceRole> {
|
||||
@override
|
||||
DeviceRole build() {
|
||||
_loadRole();
|
||||
return DeviceRole.unknown;
|
||||
}
|
||||
|
||||
Future<void> _loadRole() async {
|
||||
final repository = ref.read(setupRepositoryProvider);
|
||||
state = await repository.getRole();
|
||||
}
|
||||
|
||||
Future<void> setRole(DeviceRole role) async {
|
||||
final repository = ref.read(setupRepositoryProvider);
|
||||
await repository.setRole(role);
|
||||
state = role;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../../data/repositories/setup_repository.dart';
|
||||
import '../providers/setup_providers.dart';
|
||||
|
||||
|
||||
class SetupScreen extends ConsumerWidget {
|
||||
const SetupScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: AppColors.backgroundGradient,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Spacer(),
|
||||
// Logo
|
||||
Hero(
|
||||
tag: 'logo',
|
||||
child: SvgPicture.asset(
|
||||
'assets/logo/fastwatcher-logo.svg',
|
||||
height: 120,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'FastWatcher',
|
||||
style: Theme.of(context).textTheme.displayMedium?.copyWith(
|
||||
letterSpacing: -1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Choose your device role to continue',
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
const Spacer(),
|
||||
// Role Selection Cards
|
||||
_RoleCard(
|
||||
title: 'I am a Phone',
|
||||
subtitle: 'Send links to your TV',
|
||||
icon: Icons.phone_android_rounded,
|
||||
color: AppColors.primary,
|
||||
onTap: () {
|
||||
ref.read(deviceRoleProvider.notifier).setRole(DeviceRole.phone);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_RoleCard(
|
||||
title: 'I am a TV',
|
||||
subtitle: 'Receive and play videos',
|
||||
icon: Icons.tv_rounded,
|
||||
color: AppColors.secondary,
|
||||
onTap: () {
|
||||
ref.read(deviceRoleProvider.notifier).setRole(DeviceRole.tv);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class _RoleCard extends StatelessWidget {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _RoleCard({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.05),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
import 'features/setup/presentation/screens/setup_screen.dart';
|
||||
import 'features/setup/presentation/providers/setup_providers.dart';
|
||||
import 'features/setup/data/repositories/setup_repository.dart';
|
||||
import 'features/receiver/presentation/screens/tv_home_screen.dart';
|
||||
import 'features/sender/presentation/screens/mobile_sender_screen.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Initialize MediaKit for video playback
|
||||
MediaKit.ensureInitialized();
|
||||
|
||||
runApp(
|
||||
const ProviderScope(
|
||||
child: FastWatcherApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class FastWatcherApp extends ConsumerWidget {
|
||||
const FastWatcherApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final role = ref.watch(deviceRoleProvider);
|
||||
|
||||
return MaterialApp(
|
||||
title: 'FastWatcher',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.darkTheme,
|
||||
home: role == DeviceRole.unknown
|
||||
? const SetupScreen()
|
||||
: role == DeviceRole.phone
|
||||
? const MobileSenderScreen()
|
||||
: const TVHomeScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user