Fix errors on review page, show text when no reviews
This commit is contained in:
		
							parent
							
								
									90fccde9e6
								
							
						
					
					
						commit
						eca2b6324b
					
				@ -14,10 +14,14 @@ class ReviewListPage extends StatefulWidget {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class _ReviewListState extends State<ReviewListPage> {
 | 
					class _ReviewListState extends State<ReviewListPage> {
 | 
				
			||||||
  List<models.User> users = [];
 | 
					  List<models.User> _users = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  models.User? _getReviewUser(models.Review review) {
 | 
					  models.User? _getReviewUser(models.Review review) {
 | 
				
			||||||
    return users.firstWhere((user) => user.id == review.userId);
 | 
					    try {
 | 
				
			||||||
 | 
					      return _users.firstWhere((user) => user.id == review.userId);
 | 
				
			||||||
 | 
					    } catch(e) {
 | 
				
			||||||
 | 
					      return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
@ -27,14 +31,18 @@ class _ReviewListState extends State<ReviewListPage> {
 | 
				
			|||||||
    final arg = ModalRoute.of(context)!.settings.arguments as models.ReviewList;
 | 
					    final arg = ModalRoute.of(context)!.settings.arguments as models.ReviewList;
 | 
				
			||||||
    final reviews = arg.reviews;
 | 
					    final reviews = arg.reviews;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (reviews.isEmpty) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    final userIds = reviews.map((review) => review.userId).toSet().toList();
 | 
					    final userIds = reviews.map((review) => review.userId).toSet().toList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    final response = await api.request(context, api.ApiService.auth, 'GET', '/api/Users/UsersByIds?userIds=' + userIds.join(','), null);
 | 
					    final response = await api.request(context, api.ApiService.auth, 'GET', '/api/Users/UsersByIds?userIds=' + userIds.join(','), null);
 | 
				
			||||||
    if (response == null) return;
 | 
					    if (response == null) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    debugPrint('response: ' + response);
 | 
					    setState(() {
 | 
				
			||||||
 | 
					      _users = (jsonDecode(response) as List<dynamic>).map((user) => models.User.fromJson(user)).toList();
 | 
				
			||||||
    users = (jsonDecode(response) as List<dynamic>).map((user) => models.User.fromJson(user)).toList();
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
@ -47,12 +55,15 @@ class _ReviewListState extends State<ReviewListPage> {
 | 
				
			|||||||
      selectedIndex: -1,
 | 
					      selectedIndex: -1,
 | 
				
			||||||
      body: Scaffold(
 | 
					      body: Scaffold(
 | 
				
			||||||
        backgroundColor: const Color(0xFFF9F9F9),
 | 
					        backgroundColor: const Color(0xFFF9F9F9),
 | 
				
			||||||
        body: SingleChildScrollView(child: Container(
 | 
					        body: reviews.isEmpty
 | 
				
			||||||
 | 
					          ? const Center(child: Text('No reviews yet. Be the first to review this place'))
 | 
				
			||||||
 | 
					          : SingleChildScrollView(child: Container(
 | 
				
			||||||
            decoration: const BoxDecoration(color: Color(0xFFF9F9F9)),
 | 
					            decoration: const BoxDecoration(color: Color(0xFFF9F9F9)),
 | 
				
			||||||
            width: MediaQuery.of(context).size.width,
 | 
					            width: MediaQuery.of(context).size.width,
 | 
				
			||||||
            padding: const EdgeInsets.all(20.0),
 | 
					            padding: const EdgeInsets.all(20.0),
 | 
				
			||||||
          child: Column(children:
 | 
					            child: Column(children: [
 | 
				
			||||||
            reviews.map((review) => Container(
 | 
					              for (final review in reviews)
 | 
				
			||||||
 | 
					                Container(
 | 
				
			||||||
                  width: double.infinity,
 | 
					                  width: double.infinity,
 | 
				
			||||||
                  padding: const EdgeInsets.all(20),
 | 
					                  padding: const EdgeInsets.all(20),
 | 
				
			||||||
                  margin: const EdgeInsets.only(bottom: 10),
 | 
					                  margin: const EdgeInsets.only(bottom: 10),
 | 
				
			||||||
@ -94,8 +105,8 @@ class _ReviewListState extends State<ReviewListPage> {
 | 
				
			|||||||
                      ),
 | 
					                      ),
 | 
				
			||||||
                    ],
 | 
					                    ],
 | 
				
			||||||
                  ),
 | 
					                  ),
 | 
				
			||||||
            )).toList(),
 | 
					 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
 | 
					            ]),
 | 
				
			||||||
          )),
 | 
					          )),
 | 
				
			||||||
        floatingActionButton: FloatingActionButton(
 | 
					        floatingActionButton: FloatingActionButton(
 | 
				
			||||||
          onPressed: () async {
 | 
					          onPressed: () async {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user