import 'dart:html' as html;
import 'dart:io' as io;
import 'package:flutter/material.dart';
import 'chat_screen.dart';
import 'backend.dart';
class Config {
static String? backendUrl; // Declare it as nullable
static void loadConfig() {
// Check the platform for web or other
if (html.window.location.origin.isNotEmpty) {
// For web applications
backendUrl = html.window.location.origin; // Get the server URL from window.location
} else if (io.Platform.environment.containsKey('BACKEND_URL')) {
// For Android or other platforms, check for the environment variable
backendUrl = io.Platform.environment['BACKEND_URL'];
} else {
// If no value is determined, set it to null
backendUrl = null;
}
}
}
void main() {
Config.loadConfig(); // Load the configuration before running the app
Backend.setup('${Config.backendUrl}/ws');
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Chat',
theme: ThemeData.dark(),
home: const ChatScreen(),
);
}
}