import
'package:flutter/material.dart'
;
import
'package:flutter_insta/flutter_insta.dart'
;
void
main() {
runApp(
const
MyApp());
}
class
MyApp extends StatelessWidget {
const
MyApp({super.key});
@override
Widget build(BuildContext context) {
return
MaterialApp(
debugShowCheckedModeBanner:
false
,
title:
'Instagram Profile Fetcher'
,
theme: ThemeData(
primarySwatch: Colors.green,
),
home:
const
InstagramProfile(),
);
}
}
class
InstagramProfile extends StatefulWidget {
const
InstagramProfile({super.key});
@override
createState() => _InstagramProfileState();
}
class
_InstagramProfileState extends State<InstagramProfile> {
FlutterInsta flutterInsta = FlutterInsta();
String username =
""
;
String? followers =
"0"
;
String following =
"0"
;
String profilePic =
""
;
String userNameDisplay =
""
;
@override
void
initState() {
super.initState();
}
fetchData() async {
try
{
await flutterInsta.getProfileData(username);
setState(() {
followers = flutterInsta.followers;
following = flutterInsta.following;
profilePic = flutterInsta.imgurl;
userNameDisplay = flutterInsta.username;
});
}
catch
(e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
return
Scaffold(
appBar: AppBar(title:
const
Text(
'GFG - Instagram Profile Data'
)),
body: Padding(
padding:
const
EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
onChanged: (value) {
setState(() {
username = value;
});
},
decoration:
const
InputDecoration(labelText:
'Enter Instagram Username'
),
),
ElevatedButton(
onPressed: () async {
await fetchData();
},
child:
const
Text(
'Fetch Data'
),
),
const
SizedBox(height: 20),
profilePic ==
""
?
const
Icon(
Icons.person_2_outlined,
size: 40,
)
: CircleAvatar(
backgroundImage: NetworkImage(profilePic),
radius: 50,
),
const
SizedBox(height: 20),
Text(
userNameDisplay,
style:
const
TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
'Followers: $followers'
,
style:
const
TextStyle(fontSize: 20),
),
Text(
'Following: $following'
,
style:
const
TextStyle(fontSize: 20),
),
],
)
],
),
),
);
}
}