php lime en frontend flutter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comments_component.dart 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_forum/Providers/comments_provider.dart';
  3. import 'package:provider/provider.dart';
  4. class CommentsComponent extends StatelessWidget {
  5. final String id;
  6. CommentsComponent({required this.id});
  7. @override
  8. Widget build(BuildContext context) {
  9. return FutureBuilder(
  10. future: Provider.of<CommentsProvider>(context, listen: false).getComments(id),
  11. builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
  12. if (snapshot.connectionState == ConnectionState.waiting) {
  13. return const Center(child: CircularProgressIndicator());
  14. } else if (snapshot.hasError) {
  15. return Center(child:Text(snapshot.error.toString()));
  16. } else {
  17. return Consumer<CommentsProvider>(
  18. child: const Center(child: Text('Got no comments yet, adding some comment !')),
  19. builder: (ctx, CommentsProvider, child) => CommentsProvider.comments.isEmpty ? child! :
  20. ListView.builder(
  21. padding: EdgeInsets.only(top: 15,bottom: 15),
  22. itemCount: CommentsProvider.comments.length,
  23. scrollDirection: Axis.vertical,
  24. shrinkWrap: true,
  25. itemBuilder: (context, index){
  26. return Card(
  27. child: ListTile(
  28. leading: const Icon(Icons.account_circle),
  29. title: Text('user id:'+CommentsProvider.comments[index].id.toString()),
  30. subtitle: Text(CommentsProvider.comments[index].comment.toString()),
  31. dense: true,
  32. ),
  33. );
  34. },
  35. ),
  36. );
  37. }
  38. },
  39. );
  40. }
  41. }