first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../domain/adapters/repository_adapter.dart';
|
||||
import '../../domain/entity/cases_model.dart';
|
||||
|
||||
class HomeController extends SuperController<CasesModel> {
|
||||
HomeController({required this.homeRepository});
|
||||
|
||||
final IHomeRepository homeRepository;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
//Loading, Success, Error handle with 1 line of code
|
||||
append(() => homeRepository.getCases);
|
||||
}
|
||||
|
||||
Country getCountryById(String id) {
|
||||
final index = int.tryParse(id);
|
||||
if (index != null) {
|
||||
return state!.countries[index];
|
||||
}
|
||||
|
||||
return state!.countries.first;
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
print('The build method is done. '
|
||||
'Your controller is ready to call dialogs and snackbars');
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
print('onClose called');
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeMetrics() {
|
||||
print('the window size did change');
|
||||
super.didChangeMetrics();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangePlatformBrightness() {
|
||||
print('platform change ThemeMode');
|
||||
super.didChangePlatformBrightness();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> didPushRoute(String route) {
|
||||
print('the route $route will be open');
|
||||
return super.didPushRoute(route);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> didPopRoute() {
|
||||
print('the current route will be closed');
|
||||
return super.didPopRoute();
|
||||
}
|
||||
|
||||
@override
|
||||
void onDetached() {
|
||||
print('onDetached called');
|
||||
}
|
||||
|
||||
@override
|
||||
void onInactive() {
|
||||
print('onInative called');
|
||||
}
|
||||
|
||||
@override
|
||||
void onPaused() {
|
||||
print('onPaused called');
|
||||
}
|
||||
|
||||
@override
|
||||
void onResumed() {
|
||||
print('onResumed called');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/home_controller.dart';
|
||||
|
||||
class CountryView extends GetView<HomeController> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
colorFilter: ColorFilter.linearToSrgbGamma(),
|
||||
image: NetworkImage(
|
||||
"https://images.pexels.com/photos/3902882/pexels-photo-3902882.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"))),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0),
|
||||
child: Container(
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
title: Text('corona_by_country'.tr),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Center(
|
||||
child: ListView.builder(
|
||||
itemCount: controller.state!.countries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final country = controller.state!.countries[index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
//Get.rootDelegate.toNamed('/home/country');
|
||||
Get.rootDelegate
|
||||
.toNamed('/home/country/details?id=$index');
|
||||
},
|
||||
trailing: CircleAvatar(
|
||||
backgroundImage: NetworkImage(
|
||||
"https://flagpedia.net/data/flags/normal/${country.countryCode.toLowerCase()}.png"),
|
||||
),
|
||||
title: Text(country.country),
|
||||
subtitle: Text(
|
||||
// ignore: lines_longer_than_80_chars
|
||||
'${'total_infecteds'.tr}${' ${country.totalConfirmed}'}'),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/home_controller.dart';
|
||||
|
||||
class DetailsView extends GetView<HomeController> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final parameter = Get.rootDelegate.parameters;
|
||||
final country = controller.getCountryById(parameter['id'] ?? '');
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
colorFilter: ColorFilter.linearToSrgbGamma(),
|
||||
image: NetworkImage(
|
||||
"https://flagpedia.net/data/flags/normal/${country.countryCode.toLowerCase()}.png"),
|
||||
),
|
||||
),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0),
|
||||
child: Container(
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
title: Text('details'.tr),
|
||||
backgroundColor: Colors.black12,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${country.country}',
|
||||
style: TextStyle(fontSize: 45, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
),
|
||||
Text(
|
||||
'total_confirmed'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${country.totalConfirmed}',
|
||||
style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
'total_deaths'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${country.totalDeaths}',
|
||||
style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
'total_recovered'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${country.totalRecovered}',
|
||||
style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/home_controller.dart';
|
||||
|
||||
class HomeView extends GetView<HomeController> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
colorFilter: ColorFilter.linearToSrgbGamma(),
|
||||
image: NetworkImage(
|
||||
"https://images.pexels.com/photos/3902882/pexels-photo-3902882.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"),
|
||||
),
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
Get.snackbar('title', 'message');
|
||||
},
|
||||
),
|
||||
title: Text('covid'.tr),
|
||||
backgroundColor: Colors.white10,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Center(
|
||||
child: controller.obx(
|
||||
(state) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 100,
|
||||
),
|
||||
Text(
|
||||
'total_confirmed'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${state!.global.totalConfirmed}',
|
||||
style: TextStyle(fontSize: 45, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
'total_deaths'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${state.global.totalDeaths}',
|
||||
style: TextStyle(fontSize: 45, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
textStyle: TextStyle(color: Colors.black),
|
||||
side: BorderSide(
|
||||
color: Colors.deepPurple,
|
||||
width: 3,
|
||||
),
|
||||
shape: StadiumBorder(),
|
||||
),
|
||||
onPressed: () async {
|
||||
final data =
|
||||
await Get.rootDelegate.toNamed('/home/country');
|
||||
print('DATA: $data');
|
||||
},
|
||||
child: Text(
|
||||
'fetch_country'.tr,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
textStyle: TextStyle(color: Colors.black),
|
||||
side: BorderSide(
|
||||
color: Colors.deepPurple,
|
||||
width: 3,
|
||||
),
|
||||
shape: StadiumBorder(),
|
||||
),
|
||||
onPressed: () {
|
||||
Get.updateLocale(Locale('pt', 'BR'));
|
||||
},
|
||||
child: Text(
|
||||
'Update language to Portuguese',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user