comment_input_bar_widget.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:news_app/constant/color_res.dart';
  5. import 'package:news_app/constant/size_res.dart';
  6. import 'package:news_app/widget/my_txt.dart';
  7. import '../../widget/auth_gesture_detector.dart';
  8. /// @author: bo.zeng
  9. /// @email: cnhbwds@gmail.com
  10. /// @date: 2025 2025/4/17 12:22
  11. /// @description:
  12. class CommentInputBarWidget extends ConsumerStatefulWidget {
  13. final FocusNode focusNode;
  14. final String id;
  15. final Function(String)? onSend;
  16. const CommentInputBarWidget(
  17. this.focusNode,
  18. this.onSend,
  19. this.id, {
  20. super.key,
  21. });
  22. @override
  23. ConsumerState<ConsumerStatefulWidget> createState() =>
  24. _CommentInputBarState();
  25. }
  26. class _CommentInputBarState extends ConsumerState<CommentInputBarWidget> {
  27. final TextEditingController _controller = TextEditingController();
  28. @override
  29. Widget build(BuildContext context) {
  30. double size = MediaQuery.of(context).padding.bottom;
  31. return Container(
  32. decoration: BoxDecoration(
  33. color: Colors.white,
  34. border: Border(top: BorderSide(color: colorE5E5E5, width: 0.5)),
  35. ),
  36. padding: EdgeInsets.only(
  37. top: horizontalPadding,
  38. bottom: size > 0 ? size : horizontalPadding,
  39. ),
  40. child: Row(
  41. children: [
  42. Expanded(
  43. child: Container(
  44. height: 40.h,
  45. margin: EdgeInsets.only(right: 10.w),
  46. child: TextField(
  47. decoration: InputDecoration(
  48. fillColor: colorF5F7FA,
  49. filled: true,
  50. border: OutlineInputBorder(
  51. borderRadius: BorderRadius.circular(5.r),
  52. borderSide: BorderSide.none,
  53. ),
  54. contentPadding: EdgeInsets.symmetric(
  55. horizontal: 10.w,
  56. vertical: 20.h,
  57. ),
  58. hintText: '快来写下你的评论吧~',
  59. hintStyle: TextStyle(color: color7788A0, fontSize: 12.sp),
  60. ),
  61. focusNode: widget.focusNode,
  62. controller: _controller,
  63. ),
  64. ),
  65. ),
  66. if (widget.focusNode.hasFocus)
  67. AuthGestureDetector(
  68. onTap: () {
  69. widget.onSend?.call(_controller.text);
  70. _controller.clear();
  71. },
  72. child: Container(
  73. width: 50.w,
  74. padding: EdgeInsets.symmetric(vertical: 5.h),
  75. alignment: Alignment.center,
  76. decoration: BoxDecoration(
  77. color: color188FFF,
  78. borderRadius: BorderRadius.circular(5.r),
  79. ),
  80. child: myTxt(text: "发送", color: Colors.white, fontSize: 12.sp),
  81. ),
  82. ),
  83. ],
  84. ),
  85. );
  86. }
  87. }