Created
February 4, 2025 10:42
-
-
Save prakhart111/8460b70ce3300463352436babf078875 to your computer and use it in GitHub Desktop.
Snippet created via Next.js API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Airbnb Clone', | |
theme: ThemeData( | |
primarySwatch: Colors.pink, | |
fontFamily: 'Circular', | |
), | |
home: const HomePage(), | |
); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override | |
State<HomePage> createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
final List<Map<String, dynamic>> _listings = [ | |
{ | |
'image': 'https://placehold.co/600x400', | |
'title': 'Modern Apartment in Downtown', | |
'location': 'New York, USA', | |
'price': 150, | |
'rating': 4.8, | |
}, | |
{ | |
'image': 'https://placehold.co/600x400', | |
'title': 'Cozy Beach House', | |
'location': 'Miami, USA', | |
'price': 200, | |
'rating': 4.9, | |
}, | |
{ | |
'image': 'https://placehold.co/600x400', | |
'title': 'Mountain Cabin Retreat', | |
'location': 'Colorado, USA', | |
'price': 175, | |
'rating': 4.7, | |
}, | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Colors.white, | |
elevation: 0, | |
title: const Text( | |
'Airbnb', | |
style: TextStyle( | |
color: Colors.pink, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
actions: [ | |
IconButton( | |
icon: const Icon(Icons.search, color: Colors.black), | |
onPressed: () {}, | |
), | |
IconButton( | |
icon: const Icon(Icons.person_outline, color: Colors.black), | |
onPressed: () {}, | |
), | |
], | |
), | |
body: SingleChildScrollView( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
const Padding( | |
padding: EdgeInsets.all(16.0), | |
child: Text( | |
'Where to?', | |
style: TextStyle( | |
fontSize: 28, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
), | |
Container( | |
height: 50, | |
margin: const EdgeInsets.symmetric(horizontal: 16), | |
child: ListView( | |
scrollDirection: Axis.horizontal, | |
children: [ | |
_buildFilterChip('Anywhere'), | |
_buildFilterChip('Any week'), | |
_buildFilterChip('Add guests'), | |
], | |
), | |
), | |
GridView.builder( | |
shrinkWrap: true, | |
physics: const NeverScrollableScrollPhysics(), | |
padding: const EdgeInsets.all(16), | |
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: MediaQuery.of(context).size.width > 600 ? 3 : 1, | |
childAspectRatio: 1.1, | |
mainAxisSpacing: 16, | |
crossAxisSpacing: 16, | |
), | |
itemCount: _listings.length, | |
itemBuilder: (context, index) { | |
final listing = _listings[index]; | |
return _buildListingCard(listing); | |
}, | |
), | |
], | |
), | |
), | |
bottomNavigationBar: BottomNavigationBar( | |
type: BottomNavigationBarType.fixed, | |
selectedItemColor: Colors.pink, | |
unselectedItemColor: Colors.grey, | |
items: const [ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.search), | |
label: 'Explore', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.favorite_border), | |
label: 'Wishlists', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.trip_origin), | |
label: 'Trips', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.message_outlined), | |
label: 'Inbox', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.person_outline), | |
label: 'Profile', | |
), | |
], | |
), | |
); | |
} | |
Widget _buildFilterChip(String label) { | |
return Container( | |
margin: const EdgeInsets.only(right: 8), | |
child: FilterChip( | |
label: Text(label), | |
onSelected: (bool selected) {}, | |
selected: false, | |
backgroundColor: Colors.grey[200], | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(20), | |
), | |
), | |
); | |
} | |
Widget _buildListingCard(Map<String, dynamic> listing) { | |
return Card( | |
elevation: 2, | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(12), | |
), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Expanded( | |
child: ClipRRect( | |
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)), | |
child: Image.network( | |
listing['image'], | |
fit: BoxFit.cover, | |
width: double.infinity, | |
), | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.all(12), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
Text( | |
listing['title'], | |
style: const TextStyle( | |
fontWeight: FontWeight.bold, | |
fontSize: 16, | |
), | |
), | |
Row( | |
children: [ | |
const Icon(Icons.star, size: 16), | |
Text(listing['rating'].toString()), | |
], | |
), | |
], | |
), | |
const SizedBox(height: 4), | |
Text( | |
listing['location'], | |
style: TextStyle(color: Colors.grey[600]), | |
), | |
const SizedBox(height: 4), | |
Text( | |
'\$${listing['price']} / night', | |
style: const TextStyle(fontWeight: FontWeight.bold), | |
), | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment