diff --git a/assets/sol-tenerife.jpeg b/assets/sol-tenerife.jpeg new file mode 100644 index 0000000..42fad20 Binary files /dev/null and b/assets/sol-tenerife.jpeg differ diff --git a/lib/main.dart b/lib/main.dart index 770f51f..ee2b245 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -49,6 +49,7 @@ class MainPageState extends State{ onTap: (int index) { setState(() { _selectedPage = index; + cnt = ''; }); }, items: [ diff --git a/lib/otb.dart b/lib/otb.dart index c8467eb..26467d7 100644 --- a/lib/otb.dart +++ b/lib/otb.dart @@ -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); @@ -50,12 +52,12 @@ class MyCustomForm extends StatefulWidget { class MyCustomFormState extends State { final _formKey = GlobalKey(); - 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 getData() async { + Future getData(dynamic country) async { var response = await http.get( - Uri.encodeFull(url), + Uri.encodeFull(url+country), headers: { 'Accept': 'application/json' } @@ -64,7 +66,7 @@ class MyCustomFormState extends State { List data = json.decode(response.body); print(data); } catch(_) { - print('WTF'); + print('Authentication Error'); } } @override @@ -80,34 +82,73 @@ class MyCustomFormState extends State { 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( + builder: (BuildContext context) { + return Scaffold( + appBar: AppBar( + title: + Text( + "Holiday Results", + ), ), + body: ListView( + // child: FlatButton( + // child: Text('POP'), + // onPressed: () { + // Navigator.pop(context); + // }, + // ), + children: [ + 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: [ + 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( @@ -120,3 +161,51 @@ class MyCustomFormState extends State { ); } } + + + +class DropdownExample extends StatefulWidget { + @override + _DropdownExampleState createState() { + return _DropdownExampleState(); + } + } + + class _DropdownExampleState extends State { + String _value; + + @override + Widget build(BuildContext context) { + return Center( + + child: DropdownButton( + items: [ + DropdownMenuItem( + child: Text('Malta'), + value: 'malta', + ), + DropdownMenuItem( + child: Text('Kathmandu'), + value: 'ktm', + ), + DropdownMenuItem( + 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, + ), + ); + } + } +