Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/sol-tenerife.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MainPageState extends State<MainPage>{
onTap: (int index) {
setState(() {
_selectedPage = index;
cnt = '';
});
},
items: [
Expand Down
135 changes: 112 additions & 23 deletions lib/otb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'dart:convert';

void main() => runApp(new Otb());

String cnt;

class Otb extends StatelessWidget {
Color gradientStart = const Color(0xff00b5ea); //Change start gradient color here
Color gradientEnd = const Color(0xffffffff);
Expand Down Expand Up @@ -50,12 +52,12 @@ class MyCustomForm extends StatefulWidget {
class MyCustomFormState extends State<MyCustomForm> {
final _formKey = GlobalKey<FormState>();

String url = 'http://localhost:3001/api/v1/search/holidays?country=UK';
String url = 'http://localhost:3001/api/v1/search/holidays?country=';
// I have used my own private app's API endpoint here

Future<String> getData() async {
Future<String> getData(dynamic country) async {
var response = await http.get(
Uri.encodeFull(url),
Uri.encodeFull(url+country),
headers: {
'Accept': 'application/json'
}
Expand All @@ -64,7 +66,7 @@ class MyCustomFormState extends State<MyCustomForm> {
List data = json.decode(response.body);
print(data);
} catch(_) {
print('WTF');
print('Authentication Error');
}
}
@override
Expand All @@ -80,34 +82,73 @@ class MyCustomFormState extends State<MyCustomForm> {
height: 150,
width: 200,
),
TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
labelText: 'Where To'
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter your destination.';
}
return null;
},
),
DropdownExample(),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
if (cnt != null && !cnt.isEmpty) {
// If the form is valid, display a Snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text('Searching Holidays..')));
getData();
getData(cnt);
Navigator.push(context, MaterialPageRoute<void>(
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
title:
Text(
"Holiday Results",
), ),
body: ListView(
// child: FlatButton(
// child: Text('POP'),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
children: <Widget>[
Container(
margin:EdgeInsets.all(8.0),
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: InkWell(
onTap: () => print("ciao"),
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8.0),
topRight: Radius.circular(8.0),
),
child: Image.network(
'https://i.onthebeach.co.uk/v1/hotel_images/7bc4f24e-2c59-4f6f-bd2e-8655c2cd5f1d/cover/767/620/medium/1.0/sol-tenerife',
width: 300,
height: 150,
fit:BoxFit.fill


),
),
ListTile(
title: Text('Sol Tenerife'),
subtitle: Text('Tenerife'),
),
],
),
),
),
),
],
),
);
},
));
print("Country: " + cnt);
}
else {
Scaffold.of(context)
.showSnackBar(SnackBar(duration: Duration(seconds: 1), content: Text("Validation error")));
}
},
textColor: Color(0xff17317f),

color: Colors.yellow,
padding: const EdgeInsets.all(8.0),
child: Text(
Expand All @@ -120,3 +161,51 @@ class MyCustomFormState extends State<MyCustomForm> {
);
}
}



class DropdownExample extends StatefulWidget {
@override
_DropdownExampleState createState() {
return _DropdownExampleState();
}
}

class _DropdownExampleState extends State<DropdownExample> {
String _value;

@override
Widget build(BuildContext context) {
return Center(

child: DropdownButton<String>(
items: [
DropdownMenuItem<String>(
child: Text('Malta'),
value: 'malta',
),
DropdownMenuItem<String>(
child: Text('Kathmandu'),
value: 'ktm',
),
DropdownMenuItem<String>(
child: Text('UK'),
value: 'UK',
),
],
onChanged: (String value) {
setState(() {
_value = value;
cnt = value;
});
},
hint: Text('Where To'),
value: _value,
iconEnabledColor: Colors.yellow,
isExpanded: true,
isDense: true,
),
);
}
}