main.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 'package:gmus/components/apiurl.dart';
  6. import './config.dart';
  7. import './controller.dart';
  8. import './preferences.dart';
  9. import './components/content.dart';
  10. import './components/status.dart';
  11. class Gmus extends StatelessWidget {
  12. final Preferences storedPreferences;
  13. Gmus({
  14. @required this.storedPreferences,
  15. });
  16. @override
  17. Widget build(BuildContext context) {
  18. Get.put(Controller(
  19. apiUrl: this.storedPreferences.apiUrl.obs,
  20. name: this.storedPreferences.clientName.obs,
  21. ));
  22. return Scaffold(
  23. appBar: AppBar(
  24. title: Text('gmus'),
  25. ),
  26. body: Container(
  27. child: Column(
  28. children: [
  29. Expanded(
  30. child: Content(),
  31. ),
  32. StatusBar(),
  33. ],
  34. ),
  35. ),
  36. drawer: Drawer(
  37. child: ListView(
  38. padding: EdgeInsets.only(top: 40.0),
  39. children: <Widget>[
  40. ListTile(
  41. title: Text('Set API URL'),
  42. onTap: () {
  43. showDialog(
  44. context: context,
  45. builder: widgetBuilderSetApiUrl,
  46. );
  47. },
  48. ),
  49. ],
  50. ),
  51. ),
  52. );
  53. }
  54. }
  55. class MyHttpOverrides extends HttpOverrides {
  56. @override
  57. HttpClient createHttpClient(SecurityContext context) {
  58. return super.createHttpClient(context)
  59. ..badCertificateCallback =
  60. (X509Certificate cert, String host, int port) => true;
  61. }
  62. }
  63. Future<void> main() async {
  64. await DotEnv.load();
  65. if (config['isDevelopment']) {
  66. HttpOverrides.global = new MyHttpOverrides();
  67. }
  68. getPreferences().then((preferences) =>
  69. runApp(GetMaterialApp(home: Gmus(storedPreferences: preferences))));
  70. }