I am trying to redirect from homepage when the icon user it’s pressed to his own profile page but I receive the error: ‘LateinitializationError: Field ‘scrollController’ has not been initialised.’ what I should change to the code to make it work. I added scrollController in the UserPage and UserProfile
class UserPage extends StatefulWidget {
late ScrollController scrollController;
UserPage({super.key});
@override
State<UserPage> createState() => UserProfile();
}
class UserProfile extends State<UserPage> with SingleTickerProviderStateMixin {
bool isFileImage = false;
late User user;
late ScrollController scrollController;
late File pickedFile;
String? userImage;
String? address;
String? precise_address;
String? userName;
String? facebookUrl;
String? instagramUrl;
String? tikTokUrl;
TextEditingController facebookController = TextEditingController();
TextEditingController instagramController = TextEditingController();
TextEditingController tiktokController = TextEditingController();
late String userId;
Random randomGenerator = Random();
String? searchString;
String? country;
QuerySnapshot? querySnapshot;
Stream<QuerySnapshot<Map>>? stream;
TabController? tabController;
@override
void initState() {
tabController = TabController(
length: 3,
vsync: this,
);
tabController?.addListener(() {
setState(() {});
});
initUser();
}
final Algolia _algoliaApp = AlgoliaApplication.algolia;
String? serviveProvideId;
Future<List<AlgoliaObjectSnapshot>> _operation(String input) async {
AlgoliaQuery query = _algoliaApp.instance.index("users").search(input);
AlgoliaQuerySnapshot querySnap = await query.getObjects();
List<AlgoliaObjectSnapshot> results = querySnap.hits;
return results;
}
initUser() async {
user = FirebaseAuth.instance.currentUser!;
userId = user.uid;
logger.e("user id at init user =$userId");
getSocialData();
getData();
}
final TextEditingController _userNameController = TextEditingController();
late File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
setState(() {
_image = File(pickedFile.path);
});
Reference storageReference = FirebaseStorage.instance.ref();
Uint8List imageData = _image.readAsBytesSync();
storageReference
.child("Users Profile")
.child(userId)
.putData(imageData)
.then((uploadTask) async {
var dowurl = await uploadTask.ref.getDownloadURL();
String url = dowurl.toString();
Map<String, dynamic> urlNull = {
'avatarUrl': url,
};
DocumentReference prereference =
FirebaseFirestore.instance.collection('Users').doc(userId);
await FirebaseFirestore.instance.runTransaction((transaction) async {
transaction.update(prereference, urlNull);
});
});
}
}
// Future<void> _createDynamicLink(bool short) async {
// setState(() {
// _isCreatingLink = true;
// });
// final DynamicLinkParameters parameters = DynamicLinkParameters(
// uriPrefix: 'https://cx4k7.app.goo.gl',
// link: Uri.parse('https://tariffo.page.link/homepage'),
// androidParameters: AndroidParameters(
// packageName: 'com.svapps.tariffo',
// minimumVersion: 0,
// ),
// dynamicLinkParametersOptions: DynamicLinkParametersOptions(
// shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
// ),
// iosParameters: IosParameters(
// bundleId: 'com.google.FirebaseCppDynamicLinksTestApp.dev',
// minimumVersion: '0',
// ),
// );
// Uri url;
// if (short) {
// final ShortDynamicLink shortLink = await parameters.buildShortLink();
// url = shortLink.shortUrl;
// } else {
// url = await parameters.buildUrl();
// }
// setState(() {
// _linkMessage = url.toString();
// _isCreatingLink = false;
// });
// }
Future<void> displayPrediction(Prediction p, BuildContext context) async {
var placeId = p.placeId;
var address = await FlGeocoder(Constants.googlePlaceKey)
.findAddressesFromPlaceId(placeId!);
setState(() {
searchString = p.description!;
});
FirebaseFirestore.instance.collection('Users').doc(userId).update({
"precise_location": searchString,
});
country = address.first.country!.longName;
}
var addresses;
var first;
double lat = 0.0;
double long = 0.0;
@override
void didChangeDependencies() async {
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
void viewReview(var ratings, String name, String review, String avatarUrl) {
showGeneralDialog(
context: context,
barrierDismissible: false,
transitionDuration: const Duration(
milliseconds: 400,
), // how long it takes to popup dialog after button click
pageBuilder: (_, __, ___) {
// your widget implementation
return Container(
color: Colors.black.withOpacity(0.4),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
actions: [
IconButton(
icon: const Icon(
Icons.close,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
),
],
),
body: SafeArea(
// top: false,
child: Container(
padding: const EdgeInsets.all(8.0),
child: Container(
// color: Colors.white,
// height: MediaQuery.of(context).size.height * 0.9,
// width: MediaQuery.of(context).size.width * 1,
child: ListView(
children: [
Container(
// width: 200,
// margin: EdgeInsets.only(
// top: 8, bottom: 8, right: 12),
margin: const EdgeInsets.only(right: 12, bottom: 0),
// padding: const EdgeInsets.all(11),
// width: MediaQuery.of(context)
// .size
// .width -
// 140,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 2,
spreadRadius: 1)
],
borderRadius: BorderRadius.circular(8)),
child: Column(
children: [
Row(
children: [
CircleAvatar(
backgroundImage: const AssetImage(
'assets/images/profilepic.png'),
child: Image.network(avatarUrl),
),
const SizedBox(width: 8),
Text(name,
style: const TextStyle(
fontWeight: FontWeight.bold)),
const SizedBox(width: 50),
Row(
children: [
_buildRatingStars(ratings),
],
)
],
),
// Row(
// children: [
// _buildRatingStars(snapshot
// .data
// .docs[index]
// .data["rating"]),
// ],
// ),
// Text(
// snapshot
// .data
// .docs[index]
// .data["text"],
// overflow:
// TextOverflow.ellipsis,
// textScaleFactor: 1.1),
Container(
margin: const EdgeInsets.only(top: 8),
width: MediaQuery.of(context).size.width - 140,
child: Text(
review,
textScaleFactor: 1.1,
),
),
TextButton(
style: TextButton.styleFrom(
shape: const StadiumBorder(),
backgroundColor: Colors.black,
),
onPressed: () {
Navigator.pop(context);
},
child: const Text(
'Close',
style: TextStyle(
color: Colors.white,
),
),
),
],
),
),
],
),
),
),
),
),
);
},
);
}