insta_widgets 0.0.1+1 insta_widgets: ^0.0.1+1 copied to clipboard
You can use widgets like Instagram.
import 'package:flutter/material.dart';
import 'package:insta_widgets/insta_widgets.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: PhotoListPage(),
);
}
}
class PhotoListPage extends StatefulWidget {
const PhotoListPage({Key? key}) : super(key: key);
@override
State<PhotoListPage> createState() => _PhotoListPageState();
}
class _PhotoListPageState extends State<PhotoListPage> {
final List<String> _photos = <String>[
"https://upload.wikimedia.org/wikipedia/commons/0/0f/IU_posing_for_Marie_Claire_Korea_March_2022_issue_03.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/%E2%80%98LG_Q7_BTS_%EC%97%90%EB%94%94%EC%85%98%E2%80%99_%EC%98%88%EC%95%BD_%ED%8C%90%EB%A7%A4_%EC%8B%9C%EC%9E%91_%2842773472410%29_%28cropped%29.jpg/640px-%E2%80%98LG_Q7_BTS_%EC%97%90%EB%94%94%EC%85%98%E2%80%99_%EC%98%88%EC%95%BD_%ED%8C%90%EB%A7%A4_%EC%8B%9C%EC%9E%91_%2842773472410%29_%28cropped%29.jpg"
];
final List<InstaPhoto> _pickedPhotos = <InstaPhoto>[];
Widget _buildInstaPhoto(BuildContext context, int index) {
return InstaPhotoBuilder(
photoURL: _photos[index],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Insta Widgets Example'),
actions: [
IconButton(
icon: const Icon(Icons.camera_alt_outlined),
onPressed: () => InstaPhotoPicker.instance.takePicture(
context: context,
onTookPicture: (photo){
if(photo != null) {
setState((){
_pickedPhotos.clear();
_pickedPhotos.add(photo);
});
}
}
)
),
IconButton(
icon: const Icon(Icons.add_circle_outline_outlined),
onPressed: () => InstaPhotoPicker.instance.pickPhotos(
context: context,
onPicked: (photos) => setState(() {
_pickedPhotos.clear();
_pickedPhotos.addAll(photos);
}),
onTookPicture: (photo){
if(photo != null) setState(() => _pickedPhotos.add(photo));
},
)
)
],
),
body: Column(
children: [
SizedBox(
height: 200,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _pickedPhotos.length,
itemBuilder: (context, index) => _buildPhoto(index),
),
),
Expanded(
child: ListView.separated(
separatorBuilder: (context, index) => const SizedBox(),
itemCount: _photos.length,
itemBuilder: _buildInstaPhoto,
),
),
],
),
);
}
Image _buildPhoto(int index) {
return Image.memory(_pickedPhotos[index].cropBytes ?? _pickedPhotos[index].bytes);
}
}