Skip to content

Commit

Permalink
Domain structure and dio configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
MaironLucas committed Jun 11, 2024
1 parent 70ff20e commit 961d3e9
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 210 deletions.
4 changes: 4 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"API_KEY": "YOUR_API_KEY",
"API_HOST": "NBA_API_HOST"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

.env
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# nbapp
# NBApp
This app is designed to consume the [API-NBA](https://rapidapi.com/api-sports/api/api-nba) with the purpose of showing the NBA games and their details like teams, players, standing, etc.

A new Flutter project.
Also, this app is designed to demonstrate my knowledge on developing mobile apps using Flutter.

## Getting Started
## How to run
To run, put this additional arg to you flutter run:

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
```
--dart-define-from-file=.env
```
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions domain/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages: {}
sdks:
dart: ">=3.4.1 <4.0.0"
3 changes: 3 additions & 0 deletions domain/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: domain
environment:
sdk: '>=3.4.1 <4.0.0'
1 change: 1 addition & 0 deletions lib/common/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final baseUrl = 'https://${const String.fromEnvironment('API_HOST')}';
14 changes: 14 additions & 0 deletions lib/data/remote/data_sources/game_rds.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:dio/dio.dart';
import 'package:nbapp/common/utils.dart';

class GameRDS {
GameRDS({
required Dio dio,
}) : _dio = dio;

final Dio _dio;

Future<void> getLiveGames() async {
_dio.get('${baseUrl}/games?live=all');
}
}
30 changes: 30 additions & 0 deletions lib/data/remote/infraestructure/my_dio.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:dio/dio.dart';
import 'package:dio/io.dart';

class MyDio extends DioForNative {
@override
Future<Response<T>> request<T>(
String path, {
Object? data,
Map<String, dynamic>? queryParameters,
CancelToken? cancelToken,
Options? options,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) {
const apiKey = const String.fromEnvironment('API_KEY');
const apiHost = const String.fromEnvironment('API_HOST');
options?.headers = {
'x-rapidapi-key': apiKey,
'x-rapidapi-host': apiHost,
};
return super.request(
path,
queryParameters: queryParameters,
data: data,
options: options,
cancelToken: cancelToken,
onReceiveProgress: onReceiveProgress,
);
}
}
116 changes: 8 additions & 108 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,125 +1,25 @@
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
runApp(
const MyApp(),
);
}

class MyApp extends StatelessWidget {
const MyApp({super.key});
const MyApp({
super.key,
});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
title: 'NBApp',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
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});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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),
), // This trailing comma makes auto-formatting nicer for build methods.
home: Placeholder(),
);
}
}
47 changes: 31 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
dio:
dependency: "direct main"
description:
name: dio
sha256: "11e40df547d418cc0c4900a9318b26304e665da6fa4755399a9ff9efd09034b5"
url: "https://pub.dev"
source: hosted
version: "5.4.3+1"
domain:
dependency: "direct main"
description:
path: domain
relative: true
source: path
version: "0.0.0"
fake_async:
dependency: transitive
description:
Expand All @@ -62,19 +77,19 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
url: "https://pub.dev"
source: hosted
version: "3.0.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"
leak_tracker:
dependency: transitive
description:
Expand All @@ -99,14 +114,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
url: "https://pub.dev"
source: hosted
version: "3.0.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -192,6 +199,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
vector_math:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit 961d3e9

Please sign in to comment.