Smart comment_box for post and product comment handling
Add it to your project https://pub.dev/packages/comment_box
import 'package:comment_box/comment/comment.dart';
import 'package:flutter/material.dart';
class TestMe extends StatefulWidget {
@override
_TestMeState createState() => _TestMeState();
}
class _TestMeState extends State<TestMe> {
final formKey = GlobalKey<FormState>();
final TextEditingController commentController = TextEditingController();
List filedata = [
{
'name': 'Chuks Okwuenu',
'pic': 'https://chuksokwuenu.com/img/pic.jpg',
'message': 'I love to code'
},
{
'name': 'Biggi Man',
'pic':
'https://event.chuksokwuenu.com/images/IMG_20200522_122853_521~2.jpg',
'message': 'Very cool'
},
{
'name': 'Tunde Martins',
'pic':
'https://lh3.googleusercontent.com/gXjdVvgHcgJphBYJ_yxPyQF7gf2k4Ze4wYUj7lA9ObWYIUNBeD16H3RF6ylEGrjpbmBNVlcuSSkMa3NN=w768-h768-n-o-v1',
'message': 'Very cool'
},
{
'name': 'Biggi Man',
'pic': 'https://picsum.photos/300/30',
'message': 'Very cool'
},
];
Widget commentChild(data) {
return ListView(
children: [
for (var i = 0; i < data.length; i++)
Padding(
padding: const EdgeInsets.fromLTRB(2.0, 8.0, 2.0, 0.0),
child: ListTile(
leading: GestureDetector(
onTap: () async {
// Display the image in large form.
print("Comment Clicked");
},
child: Container(
height: 50.0,
width: 50.0,
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.all(Radius.circular(50))),
child: CircleAvatar(
radius: 50,
backgroundImage: NetworkImage(data[i]['pic'])),
),
),
title: Text(
data[i]['name'],
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(data[i]['message']),
),
)
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Comment Page"),
backgroundColor: Colors.pink,
),
body: Container(
child: CommentBox(
userImage:
"https://lh3.googleusercontent.com/a-/AOh14GjRHcaendrf6gU5fPIVd8GIl1OgblrMMvGUoCBj4g=s400",
child: commentChild(filedata),
labelText: 'Write a comment...',
errorText: 'Comment cannot be blank',
sendButtonMethod: () {
if (formKey.currentState.validate()) {
print(commentController.text);
setState(() {
var value = {
'name': 'New User',
'pic':
'https://lh3.googleusercontent.com/a-/AOh14GjRHcaendrf6gU5fPIVd8GIl1OgblrMMvGUoCBj4g=s400',
'message': commentController.text
};
filedata.insert(0, value);
});
commentController.clear();
FocusScope.of(context).unfocus();
} else {
print("Not validated");
}
},
formKey: formKey,
commentController: commentController,
backgroundColor: Colors.black,
textColor: Colors.white,
sendWidget: Icon(Icons.send_sharp, size: 30, color: Colors.white),
),
),
);
}
}
Top comments (2)
You need to add more details regarding the package with some application images.
Okay thanks