Christy Moon
 · Mom, horse fanatic, medieval enthusiast, avid gamer and entrepreneur.

Help! Unknown error compiling custom widget!

I am trying to make a widget to update a posts view count live. Currently in order to see a new view count you have to go back and then go back into the post details page.

So I asked chat gpt to help me because I am not a coder.

I had a few problems with my code and chat gpt helped me to fix them. But now flutterflow keeps saying unknown error compiling custom widget.

I have added my code below maybe someone can help me?

Here is the full code:

// Automatic FlutterFlow imports import '/backend/backend.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/widgets/index.dart'; // Imports other custom widgets import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom widget code // DO NOT REMOVE OR MODIFY THE CODE ABOVE! import 'package:cloud_firestore/cloud_firestore.dart'; class PostViewCount extends StatelessWidget { final String postId; PostViewCount({required this.postId}); @override Widget build(BuildContext context) { return StreamBuilder<DocumentSnapshot>( stream: FirebaseFirestore.instance .collection('posts') .doc(postId) .snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) { return CircularProgressIndicator(); } var postData = snapshot.data?.data() as Map<String, dynamic>?; // Explicitly cast to Map<String, dynamic> and use ? for null safety int viewCount = postData?['viewCount'] ?? 0; // Use ?. and null check return Text('View Count: $viewCount'); }, ); } } // Set your widget name, define your parameter, and then add the // boilerplate code using the button on the right!

--

I also have a parameter that says postID and is a string, isList and nullable are both unchecked.

here is also a screenshot showing my parameter

3
6 replies