· 5 years ago · Jan 16, 2021, 10:24 PM
1import 'package:flutter/material.dart';
2import 'package:flutter_spinkit/flutter_spinkit.dart';
3import '../utils/constants.dart';
4import '../widgets/user_input.dart';
5import '../services/yelp.dart';
6import '../services/location.dart';
7import '../widgets/cards.dart';
8
9class LandingScreen extends StatefulWidget {
10 LandingScreen({Key key}) : super(key: key);
11
12 @override
13 _LandingScreenState createState() => _LandingScreenState();
14}
15
16class _LandingScreenState extends State<LandingScreen> {
17 double latitude;
18 double longitude;
19 List restaurantResults;
20
21 void loadData() async {
22 // Fetching Current Location
23 Location currentLocation = Location();
24 await currentLocation.getLocation();
25 latitude = currentLocation.latitude;
26 longitude = currentLocation.longitude;
27
28 // Call To Yelp API Dastabase
29 try {
30 Yelp yelp = Yelp(latitude: latitude, longitude: longitude);
31 var resultData = await yelp.getData();
32
33 setState(() {
34 restaurantResults = resultData;
35 });
36 } catch (e) {
37 print(e);
38 }
39 }
40
41 renderRestaurants() {
42 print(restaurantResults);
43 }
44
45 @override
46 void initState() {
47 super.initState();
48 loadData();
49 }
50
51 @override
52 Widget build(BuildContext context) {
53 return Scaffold(
54 body: SafeArea(
55 child: ListView(
56 children: <Widget>[
57 Padding(
58 padding: const EdgeInsets.only(left: 20.0),
59 child: Text(
60 'Good Evening! Jack',
61 style: kGreetingTextStyle,
62 ),
63 ),
64 SizedBox(
65 height: 20.0,
66 ),
67 UserInput(),
68 SizedBox(
69 height: 40.0,
70 ),
71 renderRestaurants()
72 ],
73 ),
74 ),
75 );
76 }
77}