refactor entire frontend
This commit is contained in:
1 parent
49df72f2a1
commit
7b3326524e
17 files changed
+546
-96
No files matched your search
+14
-11
@@ -1,43 +1,46 @@
|
||||
import 'dart:html' as html;
|
||||
import 'dart:io' as io;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'backend.dart';
|
||||
import 'user_checker.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
|
||||
}
|
||||
|
||||
// For Android or other platforms, check for the environment variable
|
||||
/*if (io.Platform.environment.containsKey('BACKEND_URL')) {
|
||||
backendUrl = io.Platform.environment['BACKEND_URL'];
|
||||
} else if (html.window.location.origin.isNotEmpty) {
|
||||
// For web applications
|
||||
backendUrl = html.window.location.origin; // Get the server URL from window.location
|
||||
} else {
|
||||
// If no value is determined, set it to null
|
||||
backendUrl = null;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
print("Main");
|
||||
Config.loadConfig(); // Load the configuration before running the app
|
||||
|
||||
Backend.setup('${Config.backendUrl}/ws');
|
||||
runApp(const MyApp());
|
||||
runApp(HubApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
class HubApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Chat',
|
||||
title: 'Horde Hub',
|
||||
theme: ThemeData.dark(),
|
||||
home: const ChatScreen(),
|
||||
home: UserChecker(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user