Skip to content

Commit

Permalink
data loading indicator added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumant Raj committed Jun 4, 2019
1 parent 25f79b4 commit 958fd78
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
File renamed without changes.
36 changes: 31 additions & 5 deletions website/lib/screens/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import 'package:flutter_web/material.dart';
import 'package:website/services/github_model.dart';
import 'package:website/models/github_model.dart';
import 'package:website/services/api_service.dart';

import 'package:website/utils/raw_data.dart';
import 'package:website/widgets/table_card.dart';
import 'package:website/widgets/ticket_cards.dart';

class Dashboard extends StatelessWidget {
final List<GithubTrendingModel> data;
Dashboard({this.data});
class Dashboard extends StatefulWidget {
@override
_DashboardState createState() => _DashboardState();
}

class _DashboardState extends State<Dashboard> {
bool loading = false;
@override
void initState() {
super.initState();
getDataFromUi();
}

getDataFromUi() async {
loading = false;
await ApiData.getData();
setState(() {
loading = true;
});
}

@override
Widget build(BuildContext context) {
print(MediaQuery.of(context).size.height);
Expand Down Expand Up @@ -36,7 +55,14 @@ class Dashboard extends StatelessWidget {
SizedBox(
height: 16,
),
tableCard(context, data),
loading
? tableCard(
context,
ApiData.githubTrendingModel,
)
: Center(
child: CircularProgressIndicator(),
),
],
),
),
Expand Down
9 changes: 1 addition & 8 deletions website/lib/screens/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import 'package:flutter_web/material.dart';
import 'package:website/screens/dashboard/dashboard.dart';
import 'package:website/screens/forms/form.dart';
import 'package:website/screens/hero/hero_screen.dart';

import 'package:website/services/github_model.dart';

import 'package:website/utils/color_constants.dart';

class HomeScreen extends StatefulWidget {
final List<GithubTrendingModel> data;
HomeScreen({this.data});
@override
HomeScreenState createState() => HomeScreenState();
}
Expand Down Expand Up @@ -132,9 +127,7 @@ class HomeScreenState extends State<HomeScreen>
physics: NeverScrollableScrollPhysics(),
controller: tabController,
children: [
Dashboard(
data: widget.data,
),
Dashboard(),
FormMaterial(),
HeroAnimation(),
],
Expand Down
20 changes: 4 additions & 16 deletions website/lib/screens/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class _LoginState extends State<Login> {
@override
void initState() {
super.initState();
getDataFromUi();
}

getDataFromUi() async {
await ApiData.getData();
}

@override
Expand Down Expand Up @@ -47,17 +42,10 @@ class _LoginState extends State<Login> {
width: MediaQuery.of(context).size.width / 2.5,
child: RaisedButton(
onPressed: () {
if (ApiData.githubTrendingModel.isNotEmpty) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeScreen(
data: ApiData.githubTrendingModel,
)),
);
} else {
print("no data");
}
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomeScreen()),
);
},
padding: EdgeInsets.all(12),
color: ColorConstants.blue,
Expand Down
3 changes: 1 addition & 2 deletions website/lib/services/api_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;

import 'github_model.dart';
import 'package:website/models/github_model.dart';

class ApiData {
static List<GithubTrendingModel> githubTrendingModel;
Expand Down
3 changes: 2 additions & 1 deletion website/lib/widgets/table_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_web/material.dart';
import 'package:website/services/github_model.dart';

import 'package:website/models/github_model.dart';

Widget tableCard(BuildContext context, List<GithubTrendingModel> data) {
return Card(
Expand Down

0 comments on commit 958fd78

Please sign in to comment.