diff --git a/lib/app_module.dart b/lib/app_module.dart new file mode 100644 index 0000000..dcffca3 --- /dev/null +++ b/lib/app_module.dart @@ -0,0 +1,18 @@ +import 'package:dio/dio.dart'; +import 'package:flutter_modular/flutter_modular.dart'; + +import 'pages/email_page.dart'; +import 'pages/server_info_page.dart'; + +class AppModule extends Module { + @override + void binds(i) { + i.add(() => Dio()); + } + + @override + void routes(r) { + r.child('/', child: (context) => const EmailPage()); + r.child('/serverinfo', child: (context) => const ServerInfoPage()); + } +} diff --git a/lib/app_widget.dart b/lib/app_widget.dart new file mode 100644 index 0000000..d300398 --- /dev/null +++ b/lib/app_widget.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_modular/flutter_modular.dart'; + +class AppWidget extends StatelessWidget { + const AppWidget({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp.router( + title: 'PCast Portal', + theme: ThemeData(primarySwatch: Colors.blue), + routerConfig: Modular.routerConfig, + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index e21ac83..16fb61d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,69 +1,14 @@ import 'package:flutter/material.dart'; +import 'package:flutter_modular/flutter_modular.dart'; + +import 'app_module.dart'; +import 'app_widget.dart'; void main() { - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: Text(widget.title), - ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), - ); - } + return runApp( + ModularApp( + module: AppModule(), + child: const AppWidget(), + ), + ); } diff --git a/lib/models/monitor_model.dart b/lib/models/monitor_model.dart new file mode 100644 index 0000000..ecfcb75 --- /dev/null +++ b/lib/models/monitor_model.dart @@ -0,0 +1,21 @@ +class MonitorModel { + double? memory; + double? cpu; + double? disk; + + MonitorModel({this.memory, this.cpu, this.disk}); + + MonitorModel.fromJson(Map json) { + memory = json['memory']; + cpu = json['cpu']; + disk = json['disk']; + } + + Map toJson() { + final Map data = {}; + data['memory'] = memory; + data['cpu'] = cpu; + data['disk'] = disk; + return data; + } +} diff --git a/lib/models/user_model.dart b/lib/models/user_model.dart new file mode 100644 index 0000000..44749d0 --- /dev/null +++ b/lib/models/user_model.dart @@ -0,0 +1,72 @@ +class UserModel { + int? iD; + String? createdAt; + String? updatedAt; + String? deletedAt; + String? name; + String? companyname; + String? email; + String? phone; + String? channel; + String? url; + String? cpfcnpj; + String? usertype; + String? blocked; + String? cancelled; + int? serverid; + + UserModel( + {this.iD, + this.createdAt, + this.updatedAt, + this.deletedAt, + this.name, + this.companyname, + this.email, + this.phone, + this.channel, + this.url, + this.cpfcnpj, + this.usertype, + this.blocked, + this.cancelled, + this.serverid}); + + UserModel.fromJson(Map json) { + iD = json['ID']; + createdAt = json['CreatedAt']; + updatedAt = json['UpdatedAt']; + deletedAt = json['DeletedAt']; + name = json['name']; + companyname = json['companyname']; + email = json['email']; + phone = json['phone']; + channel = json['channel']; + url = json['url']; + cpfcnpj = json['cpfcnpj']; + usertype = json['usertype']; + blocked = json['blocked']; + cancelled = json['cancelled']; + serverid = json['serverid']; + } + + Map toJson() { + final Map data = {}; + data['ID'] = iD; + data['CreatedAt'] = createdAt; + data['UpdatedAt'] = updatedAt; + data['DeletedAt'] = deletedAt; + data['name'] = name; + data['companyname'] = companyname; + data['email'] = email; + data['phone'] = phone; + data['channel'] = channel; + data['url'] = url; + data['cpfcnpj'] = cpfcnpj; + data['usertype'] = usertype; + data['blocked'] = blocked; + data['cancelled'] = cancelled; + data['serverid'] = serverid; + return data; + } +} diff --git a/lib/pages/email_page.dart b/lib/pages/email_page.dart new file mode 100644 index 0000000..2d7f9bc --- /dev/null +++ b/lib/pages/email_page.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:pcast/utils/utils.dart'; + +class EmailPage extends StatefulWidget { + const EmailPage({super.key}); + + @override + State createState() => _EmailPageState(); +} + +class _EmailPageState extends State { + String email = ''; + String pass = 'initial'; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Container( + alignment: Alignment.center, + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.5, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Visibility( + visible: (pass == 'initial'), + child: TextField( + onSubmitted: (value) { + if (Utils.isValidEmail(value)) { + setState(() { + email = value; + pass = 'authenticate'; + }); + } + }, + textInputAction: TextInputAction.search, + decoration: const InputDecoration( + border: UnderlineInputBorder(), + labelText: 'Informe seu email e pressione enter', + ), + ), + ), + const SizedBox(height: 20), + Visibility( + visible: (pass == 'authenticate'), + child: Text( + 'Foi informado o email $email. Agora vamos pedir a senha ou vamos pedir para completar o cadastro, dependendo da situação do usuário.', + style: const TextStyle(fontSize: 20), + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/pages/server_info_page.dart b/lib/pages/server_info_page.dart new file mode 100644 index 0000000..d697bcf --- /dev/null +++ b/lib/pages/server_info_page.dart @@ -0,0 +1,71 @@ +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_modular/flutter_modular.dart'; +import 'package:pcast/models/monitor_model.dart'; + +class ServerInfoPage extends StatefulWidget { +// const ServerInfoComponent({Key? key, required this.info}) : super(key: key); + +// final MonitorModel info; + +// @override +// Widget build(BuildContext context) { +// return Column( +// children: [ +// Text(' CPU: ${info.cpu}'), +// Text('Memory: ${info.memory}'), +// Text(' Disk: ${info.disk}'), +// ], +// ); +// } +// } + + const ServerInfoPage({super.key}); + + @override + State createState() => _ServerInfoPageState(); +} + +class _ServerInfoPageState extends State { + @override + void initState() { + super.initState(); + getmemory(); + } + + Future getmemory() async { + final dio = Modular.get(); + final response = await dio.get('https://api.pcastlivetv.com/health'); + return MonitorModel.fromJson(response.data); + } + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: getmemory(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: Text('Please wait its loading...')); + } else { + if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } else { + return Scaffold( + appBar: AppBar(title: const Text('Home Page')), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text('Memory: ${snapshot.data?.memory?.toStringAsFixed(2)}%'), + Text('CPU: ${snapshot.data?.cpu?.toStringAsFixed(2)}%'), + Text('Disk: ${snapshot.data?.disk?.toStringAsFixed(2)}%'), + ], + ), + ), + ); + } + } + }, + ); + } +} diff --git a/lib/repositories/email_repository.dart b/lib/repositories/email_repository.dart new file mode 100644 index 0000000..1e7e93d --- /dev/null +++ b/lib/repositories/email_repository.dart @@ -0,0 +1,15 @@ +import 'package:dio/dio.dart'; +import 'package:flutter_modular/flutter_modular.dart'; + +import '../models/user_model.dart'; + +class EmailRepository { + EmailRepository(); + + // Get email from the API + Future getEmail(String email) async { + final dio = Modular.get(); + final response = await dio.get('https://api.pcastlivetv.com/checkuser/$email'); + return UserModel.fromJson(response.data); + } +} diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart new file mode 100644 index 0000000..0ca5246 --- /dev/null +++ b/lib/utils/utils.dart @@ -0,0 +1,5 @@ +class Utils { + static bool isValidEmail(String email) { + return RegExp(r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').hasMatch(email); + } +} diff --git a/pubspec.lock b/pubspec.lock index 8890429..5713c7f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,6 +9,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + auto_injector: + dependency: transitive + description: + name: auto_injector + sha256: "2952a4d4339ed3b65e8e54765ec68ee6ada5cb21d83cb8d39e3f6b4e690ab5ca" + url: "https://pub.dev" + source: hosted + version: "2.0.2" boolean_selector: dependency: transitive description: @@ -37,10 +45,18 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" cupertino_icons: dependency: "direct main" description: @@ -49,6 +65,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.6" + dio: + dependency: "direct main" + description: + name: dio + sha256: "417e2a6f9d83ab396ec38ff4ea5da6c254da71e4db765ad737a42af6930140b7" + url: "https://pub.dev" + source: hosted + version: "5.3.3" fake_async: dependency: transitive description: @@ -70,11 +94,27 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + flutter_modular: + dependency: "direct main" + description: + name: flutter_modular + sha256: ac6298ce1abd414286ee5a554fc45e81e358461979b5d4e02c8abd685e3b23f2 + url: "https://pub.dev" + source: hosted + version: "6.3.2" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" lints: dependency: transitive description: @@ -103,10 +143,18 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" + modular_core: + dependency: transitive + description: + name: modular_core + sha256: "5baaa460ac9d85d457d6864ef41a2194b8115a6bdeb585a684789f2d9004c892" + url: "https://pub.dev" + source: hosted + version: "3.3.2" path: dependency: transitive description: @@ -115,6 +163,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.8.3" + result_dart: + dependency: transitive + description: + name: result_dart + sha256: f28a171d55e2e1c1753b41d4d8edcaff886f103e73c575d14764913907e57928 + url: "https://pub.dev" + source: hosted + version: "1.1.0" sky_engine: dependency: transitive description: flutter @@ -132,18 +188,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -164,10 +220,26 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + uuid: + dependency: transitive + description: + name: uuid + sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" + url: "https://pub.dev" + source: hosted + version: "3.0.7" vector_math: dependency: transitive description: @@ -180,9 +252,9 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" sdks: - dart: ">=3.1.5 <4.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8dd1522..4c78489 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,90 +1,26 @@ name: pcast description: A new Flutter project. -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -# In Windows, build-name is used as the major, minor, and patch parts -# of the product and file versions while build-number is used as the build suffix. +publish_to: "none" + version: 1.0.0+1 environment: - sdk: '>=3.1.5 <4.0.0' + sdk: ">=3.1.5 <4.0.0" -# Dependencies specify other packages that your package needs in order to work. -# To automatically upgrade your package dependencies to the latest versions -# consider running `flutter pub upgrade --major-versions`. Alternatively, -# dependencies can be manually updated by changing the version numbers below to -# the latest version available on pub.dev. To see which dependencies have newer -# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + dio: ^5.3.3 + flutter_modular: ^6.3.2 dev_dependencies: flutter_test: sdk: flutter - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. flutter_lints: ^2.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 5b94a8f..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:pcast/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}