Skip to content

Commit

Permalink
fix filter and fix transition
Browse files Browse the repository at this point in the history
  • Loading branch information
athallahmaajid committed Jul 10, 2021
1 parent ff57fac commit e01c714
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 398 deletions.
187 changes: 92 additions & 95 deletions lib/country_detail.dart
Expand Up @@ -2,115 +2,112 @@ import 'package:corona_app/main_screen.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:corona_app/main_screen.dart';
import 'package:corona_app/filter.dart';

class CountryDetail extends StatelessWidget {
class CountryDetail extends StatefulWidget {
final country;
CountryDetail({Key? key, this.country}) : super(key: key);
const CountryDetail({Key? key, this.country}) : super(key: key);

@override
_CountryDetailState createState() => _CountryDetailState();
}

class _CountryDetailState extends State<CountryDetail> {
var countryData;
bool _countryLoading = true;

Future _loadCountryData() async{
countryData = await http.get(Uri.parse("https://covid19.mathdro.id/api/countries/${this.country}"));
countryData = await http.get(Uri.parse("https://covid19.mathdro.id/api/countries/${widget.country}"));
countryData = json.decode(countryData.body);
countryData = countryData as Map<String, dynamic>;
setState(() {
_countryLoading = false;
});
print(countryData);
}

@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _loadCountryData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
Widget child;
if (snapshot.connectionState == ConnectionState.done) {
child = Scaffold(
appBar: AppBar(title: Text("$country"),),
body: SingleChildScrollView(
child: Column(
children: [
SizedBox(height: MediaQuery.of(context).size.height/10,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${countryData['confirmed']['value']}", style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold),)
],
),
SizedBox(height: MediaQuery.of(context).size.height/30,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(child: Text("Total Kasus Covid 19 di $country", style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color.fromARGB(255, 128, 0, 0)), overflow: TextOverflow.ellipsis))
],
),
SizedBox(height: 60,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 160,
height: 90,
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Color.fromARGB(221, 204, 255, 170),
borderRadius: BorderRadius.circular(5)
),
child: Column(
children: [
Row(
children: [
Text("Sembuh", style: TextStyle(color: Color.fromARGB(255, 0, 128, 0), fontSize: 15))
],
),
SizedBox(height: 30),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("${countryData['recovered']['value']}", style: TextStyle(color: Color.fromARGB(255, 0, 128, 0), fontSize: 22))
],
),
],
),
),
Container(
width: 150,
height: 90,
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Color.fromARGB(221, 255, 170, 170),
borderRadius: BorderRadius.circular(5)
),
child: Column(
children: [
Row(
children: [
Text("Meninggal", style: TextStyle(color: Color.fromARGB(255, 212, 0, 0)),)
],
),
SizedBox(height: 30),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("${countryData['deaths']['value']}", style: TextStyle(color: Color.fromARGB(255, 212, 0, 0), fontSize: 22),)
],
),
],
),
)
],
),
],
return Scaffold(
appBar: AppBar(title: Text("${widget.country}"),),
body: (_countryLoading) ? LoadingWidget(callbackFunc: _loadCountryData) :
SingleChildScrollView(
child: Column(
children: [
SizedBox(height: MediaQuery.of(context).size.height/10,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${filterNumber(countryData['confirmed']['value'])}", style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold),)
],
),
SizedBox(height: MediaQuery.of(context).size.height/30,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(child: Text("Total Kasus Covid 19 di ${widget.country}", style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: Color.fromARGB(255, 128, 0, 0)), overflow: TextOverflow.ellipsis))
],
),
SizedBox(height: 60,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 160,
height: 90,
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Color.fromARGB(221, 204, 255, 170),
borderRadius: BorderRadius.circular(5)
),
child: Column(
children: [
Row(
children: [
Text("Sembuh", style: TextStyle(color: Color.fromARGB(255, 0, 128, 0), fontSize: 15))
],
),
SizedBox(height: 30),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("${filterNumber(countryData['recovered']['value'])}", style: TextStyle(color: Color.fromARGB(255, 0, 128, 0), fontSize: 22))
],
),
],
),
),
),
);
} else if (snapshot.connectionState == ConnectionState.waiting) {
child = Scaffold(body: LoadingWidget());
} else {
child = Scaffold(body: ErrorHandler());
}
return child;
}
Container(
width: 150,
height: 90,
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Color.fromARGB(221, 255, 170, 170),
borderRadius: BorderRadius.circular(5)
),
child: Column(
children: [
Row(
children: [
Text("Meninggal", style: TextStyle(color: Color.fromARGB(255, 212, 0, 0)),)
],
),
SizedBox(height: 30),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("${filterNumber(countryData['deaths']['value'])}", style: TextStyle(color: Color.fromARGB(255, 212, 0, 0), fontSize: 22),)
],
),
],
),
)
],
),
],
),
),
);
}
}


17 changes: 12 additions & 5 deletions lib/filter.dart
Expand Up @@ -4,12 +4,19 @@ String filterNumber(int number){
var limiter = 0;
var counter = 0;
for (var i = 0; i < reversed.length; i++) {
if ((limiter == 3) && (reversed[i] != reversed.last)) {
reversed.insert(i+counter, ',');
counter++;
limiter = 0;
print(reversed);
if (limiter == 3){
if (reversed.length < 6) {
reversed.insert(i, ',');
counter++;
limiter = 0;
} else if (reversed[i+counter-1] != reversed.last) {
reversed.insert(i+counter, ',');
counter++;
limiter = 0;
}
}
limiter++;
}
return reversed.reversed.toList().join();
}
}

0 comments on commit e01c714

Please sign in to comment.