import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:campus/Service/Firebase_Firestore_END.dart';
class Profile extends StatefulWidget {
File _imagefile;
@override
_ProfileState createState() => _ProfileState();
}
class _ProfileState extends State<Profile> {
String url;
**Use This Method To get URL From Firestore**
void getAvatar() async {
final FirebaseAuth auth = FirebaseAuth.instance;
final FirebaseUser user = await auth.currentUser();
final uid = user.uid;
DocumentSnapshot data = await Firebase_Firestore_END.getAccData(uid) as DocumentSnapshot;
url= data.data['Avatar'];
print("URL:"+url);
// return data.data['Avatar'];
}
@override
void initState(){
getAvatar(); //Call Methor Here
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
border:
Border.all(width: 1, color: Colors.blueGrey),
borderRadius:
BorderRadius.all(Radius.circular(50))),
child: CircleAvatar(
radius: 50,
backgroundColor: Colors.transparent,
backgroundImage: widget._imagefile != null
? FileImage(widget._imagefile)
**: CachedNetworkImageProvider(url),//Faliled Assertion Here**
),
),
],
),
),
);
}
}
What is the problem with this code? In Hot Reload It Works but If I restart The App. The Error (url=null) occurred. Can anyone help me to find the error? I tried in so many ways but I face the same error. I don't know why it's happened. I call url setter function in
initState() but every times url was null during start