Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Using Api and provider together
I am calling Get api for name and date in my profile header and also patch Api in my update profile screen now i want to use provider for upadating name immediately in my profile header now how can i use get api and provider in my profile header ??
class ProfileHeader extends StatelessWidget {
const ProfileHeader({super.key});
@override
Widget build(BuildContext context) {
final profileProvider = Provider.of ProfileProvider (context);
return Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(40.0),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(16),
),
child: Row(
children: [
const CircleAvatar(
radius: 40,
backgroundImage: AssetImage('assets/images/image.png'),
),
const SizedBox(width: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
profileProvider.name,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'Last Login: ${profileProvider.lastLogin}',
style: const TextStyle(color: Colors.white, fontSize: 13),
),
],
),
],
),
);
}
}
class ProfileHeader extends StatelessWidget {
const ProfileHeader({super.key});
@override
Widget build(BuildContext context) {
final profileProvider = Provider.of ProfileProvider (context);
return Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(40.0),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(16),
),
child: Row(
children: [
const CircleAvatar(
radius: 40,
backgroundImage: AssetImage('assets/images/image.png'),
),
const SizedBox(width: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
profileProvider.name,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'Last Login: ${profileProvider.lastLogin}',
style: const TextStyle(color: Colors.white, fontSize: 13),
),
],
),
],
),
);
}
}
Provider
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
class ProfileProvider with ChangeNotifier {
String _name = 'Loading...';
String _lastLogin = 'Loading...';
String get name = _name;
String get lastLogin = _lastLogin;
Future void fetchProfile() async {
const String url = 'https://api.vezigo.in/v1/app/profile';
final prefs = await SharedPreferences.getInstance();
final accessToken = prefs.getString('accessToken');
try {
final response = await http.get(
Uri.parse(url),
headers: {Source of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/