Last active
June 28, 2023 12:37
-
-
Save jinyongp/2eef886fac601cbee5bceebdd320a255 to your computer and use it in GitHub Desktop.
Flutter Daangn Home Page Clone
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'; | |
import 'package:flutter/cupertino.dart'; | |
void main() { | |
runApp(const MainApp()); | |
} | |
class MainApp extends StatelessWidget { | |
const MainApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
appBarTheme: const AppBarTheme( | |
backgroundColor: Colors.white, | |
foregroundColor: Colors.black, | |
actionsIconTheme: IconThemeData( | |
size: 24, | |
)), | |
), | |
home: const HomePage(), | |
); | |
} | |
} | |
class HomePage extends StatelessWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
var title = "중앙동"; | |
var imageUrls = List.generate( | |
30, (index) => "https://picsum.photos/seed/${index + 1}/200/"); | |
return Scaffold( | |
appBar: AppBar( | |
elevation: 0.5, | |
leadingWidth: 100, | |
leading: Row( | |
children: [ | |
const SizedBox(width: 16), | |
Text(title, style: const TextStyle(fontSize: 20)), | |
const Icon(Icons.keyboard_arrow_down_rounded) | |
], | |
), | |
actions: [ | |
IconButton( | |
onPressed: () {}, | |
icon: const Icon(CupertinoIcons.search), | |
), | |
IconButton( | |
onPressed: () {}, | |
icon: const Icon(Icons.menu), | |
), | |
IconButton( | |
onPressed: () {}, | |
icon: const Icon(CupertinoIcons.bell), | |
), | |
], | |
), | |
body: Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 16), | |
child: ListView.separated( | |
itemCount: imageUrls.length, | |
separatorBuilder: (context, index) { | |
return const Divider(height: 0); | |
}, | |
itemBuilder: (context, index) { | |
return Padding( | |
padding: const EdgeInsets.symmetric(vertical: 16), | |
child: Feed(imageUrl: imageUrls[index]), | |
); | |
}), | |
), | |
floatingActionButton: FloatingActionButton( | |
backgroundColor: Colors.orange, | |
onPressed: () {}, | |
child: const Icon( | |
Icons.add, | |
size: 32, | |
), | |
), | |
bottomNavigationBar: BottomNavigationBar( | |
iconSize: 24, | |
selectedFontSize: 12, | |
unselectedFontSize: 12, | |
selectedItemColor: Colors.black, | |
unselectedItemColor: Colors.black, | |
showUnselectedLabels: true, | |
type: BottomNavigationBarType.fixed, | |
items: const [ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.home_outlined), | |
activeIcon: Icon(Icons.home_rounded), | |
label: "홈"), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.my_library_books_outlined), | |
activeIcon: Icon(Icons.my_library_books_rounded), | |
label: "동네생활"), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.location_on_outlined), | |
activeIcon: Icon(Icons.location_on_rounded), | |
label: "내 근처"), | |
BottomNavigationBarItem( | |
icon: Icon(CupertinoIcons.chat_bubble_2), | |
activeIcon: Icon(CupertinoIcons.chat_bubble_2_fill), | |
label: "알림"), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.person_outline_rounded), | |
activeIcon: Icon(Icons.person_rounded), | |
label: "나의 당근"), | |
], | |
currentIndex: 0, | |
), | |
); | |
} | |
} | |
class Feed extends StatefulWidget { | |
const Feed({ | |
super.key, | |
required this.imageUrl, | |
}); | |
final String imageUrl; | |
@override | |
State<Feed> createState() => _FeedState(); | |
} | |
class _FeedState extends State<Feed> { | |
bool isFavorite = false; | |
@override | |
Widget build(BuildContext context) { | |
return Row( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
ClipRRect( | |
borderRadius: BorderRadius.circular(8.0), | |
child: Image.network( | |
widget.imageUrl, | |
width: 100, | |
height: 100, | |
)), | |
const SizedBox(width: 16), | |
Expanded( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
const Text( | |
"M1 아이패드 프로 11형(3세대) 와이파이 128GB 팝니다.", | |
style: TextStyle(fontSize: 16), | |
maxLines: 2, | |
overflow: TextOverflow.ellipsis, | |
), | |
const SizedBox(height: 4), | |
const Text("봉천동 · 6분전", | |
style: TextStyle(fontSize: 12, color: Colors.grey)), | |
const SizedBox(height: 4), | |
const Text("1,100,000원", | |
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)), | |
Row( | |
children: [ | |
const Spacer(), | |
Row( | |
children: [ | |
GestureDetector( | |
child: isFavorite | |
? const Icon( | |
Icons.favorite, | |
size: 16, | |
color: Colors.red, | |
) | |
: const Icon( | |
Icons.favorite_border, | |
size: 16, | |
), | |
onTap: () { | |
setState(() { | |
isFavorite = !isFavorite; | |
}); | |
}, | |
), | |
const SizedBox(width: 2), | |
SizedBox( | |
width: 24, | |
child: Text( | |
isFavorite ? "1" : "0", | |
style: const TextStyle(fontSize: 16), | |
), | |
) | |
], | |
) | |
], | |
) | |
], | |
), | |
) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment