main.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'dart:io';
  2. import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv;
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'config.dart';
  6. import 'socket.dart' as socket;
  7. class Controller extends GetxController {
  8. var name = ''.obs;
  9. setName(String newName) {
  10. name.value = newName;
  11. }
  12. }
  13. class Gmus extends StatelessWidget {
  14. @override
  15. Widget build(BuildContext context) {
  16. final Controller controller = Get.put(Controller());
  17. return Scaffold(
  18. appBar: AppBar(
  19. title: Text('gmus'),
  20. ),
  21. body: Container(
  22. child: Column(
  23. children: [
  24. Obx(() => Text("Name: ${controller.name}")),
  25. TextField(
  26. onChanged: controller.setName,
  27. decoration: InputDecoration(
  28. border: InputBorder.none,
  29. hintText: 'Set name',
  30. ),
  31. ),
  32. TextButton(
  33. child: Text('Connect'),
  34. onPressed: () {
  35. socket.connect(controller.name.value);
  36. },
  37. ),
  38. ],
  39. ),
  40. ),
  41. );
  42. }
  43. }
  44. class MyHttpOverrides extends HttpOverrides {
  45. @override
  46. HttpClient createHttpClient(SecurityContext context) {
  47. return super.createHttpClient(context)
  48. ..badCertificateCallback =
  49. (X509Certificate cert, String host, int port) => true;
  50. }
  51. }
  52. Future<void> main() async {
  53. await DotEnv.load(fileName: '.env');
  54. if (config['isDevelopment']) {
  55. HttpOverrides.global = new MyHttpOverrides();
  56. }
  57. runApp(GetMaterialApp(home: Gmus()));
  58. }