Created
March 11, 2025 21:47
-
-
Save prakhart111/bf5c141af63f71116a99d233290e985a 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
// Dualite Generated Code | |
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( | |
title: 'Google Photos Clone', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: const PhotoGallery(), | |
); | |
} | |
} | |
class PhotoGallery extends StatefulWidget { | |
const PhotoGallery({Key? key}) : super(key: key); | |
@override | |
_PhotoGalleryState createState() => _PhotoGalleryState(); | |
} | |
class _PhotoGalleryState extends State<PhotoGallery> { | |
int _selectedIndex = 0; | |
final List<String> _dummyPhotos = List.generate( | |
20, | |
(index) => 'https://placehold.co/400x400.png', | |
); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.white, | |
appBar: AppBar( | |
backgroundColor: Colors.white, | |
elevation: 0, | |
title: const Text( | |
'Google Photos', | |
style: TextStyle(color: Colors.black), | |
), | |
actions: [ | |
IconButton( | |
icon: const Icon(Icons.search, color: Colors.black), | |
onPressed: () {}, | |
), | |
IconButton( | |
icon: const Icon(Icons.account_circle_outlined, color: Colors.black), | |
onPressed: () {}, | |
), | |
], | |
), | |
body: Column( | |
children: [ | |
Container( | |
height: 40, | |
padding: const EdgeInsets.symmetric(horizontal: 16), | |
child: ListView( | |
scrollDirection: Axis.horizontal, | |
children: [ | |
_buildChip('Photos', 0), | |
_buildChip('Sharing', 1), | |
_buildChip('Search', 2), | |
_buildChip('Library', 3), | |
], | |
), | |
), | |
Expanded( | |
child: GridView.builder( | |
padding: const EdgeInsets.all(8), | |
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: 3, | |
mainAxisSpacing: 4, | |
crossAxisSpacing: 4, | |
), | |
itemCount: _dummyPhotos.length, | |
itemBuilder: (context, index) { | |
return Card( | |
elevation: 0, | |
child: InkWell( | |
onTap: () { | |
_showPhotoDetails(context, index); | |
}, | |
child: Image.network( | |
_dummyPhotos[index], | |
fit: BoxFit.cover, | |
), | |
), | |
); | |
}, | |
), | |
), | |
], | |
), | |
bottomNavigationBar: NavigationBar( | |
selectedIndex: _selectedIndex, | |
onDestinationSelected: (int index) { | |
setState(() { | |
_selectedIndex = index; | |
}); | |
}, | |
destinations: const [ | |
NavigationDestination( | |
icon: Icon(Icons.photo_outlined), | |
selectedIcon: Icon(Icons.photo), | |
label: 'Photos', | |
), | |
NavigationDestination( | |
icon: Icon(Icons.search_outlined), | |
selectedIcon: Icon(Icons.search), | |
label: 'Search', | |
), | |
NavigationDestination( | |
icon: Icon(Icons.share_outlined), | |
selectedIcon: Icon(Icons.share), | |
label: 'Sharing', | |
), | |
NavigationDestination( | |
icon: Icon(Icons.library_add_outlined), | |
selectedIcon: Icon(Icons.library_add), | |
label: 'Library', | |
), | |
], | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () {}, | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
Widget _buildChip(String label, int index) { | |
return Padding( | |
padding: const EdgeInsets.only(right: 8), | |
child: ChoiceChip( | |
label: Text(label), | |
selected: _selectedIndex == index, | |
onSelected: (bool selected) { | |
setState(() { | |
_selectedIndex = index; | |
}); | |
}, | |
), | |
); | |
} | |
void _showPhotoDetails(BuildContext context, int index) { | |
showModalBottomSheet( | |
context: context, | |
builder: (BuildContext context) { | |
return Container( | |
height: 300, | |
padding: const EdgeInsets.all(16), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
const Text( | |
'Photo Details', | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
IconButton( | |
icon: const Icon(Icons.close), | |
onPressed: () => Navigator.pop(context), | |
), | |
], | |
), | |
const SizedBox(height: 16), | |
Row( | |
children: [ | |
ClipRRect( | |
borderRadius: BorderRadius.circular(8), | |
child: Image.network( | |
_dummyPhotos[index], | |
height: 100, | |
width: 100, | |
fit: BoxFit.cover, | |
), | |
), | |
const SizedBox(width: 16), | |
const Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text('Date: Today'), | |
SizedBox(height: 8), | |
Text('Location: Unknown'), | |
SizedBox(height: 8), | |
Text('Size: 2.5 MB'), | |
], | |
), | |
], | |
), | |
const SizedBox(height: 24), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: [ | |
_buildActionButton(Icons.share, 'Share'), | |
_buildActionButton(Icons.edit, 'Edit'), | |
_buildActionButton(Icons.delete, 'Delete'), | |
_buildActionButton(Icons.info, 'Info'), | |
], | |
), | |
], | |
), | |
); | |
}, | |
); | |
} | |
Widget _buildActionButton(IconData icon, String label) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
IconButton( | |
icon: Icon(icon), | |
onPressed: () {}, | |
), | |
Text(label, style: const TextStyle(fontSize: 12)), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment