Hibok
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

79 行
1.8 KiB

  1. import 'package:flutter/material.dart';
  2. import 'auto_comp_iete_item.dart';
  3. class RichSuggestion extends StatelessWidget {
  4. final VoidCallback onTap;
  5. final AutoCompleteItem autoCompleteItem;
  6. RichSuggestion(this.autoCompleteItem, this.onTap);
  7. @override
  8. Widget build(BuildContext context) {
  9. return Material(
  10. child: InkWell(
  11. child: Container(
  12. padding: EdgeInsets.symmetric(
  13. horizontal: 24,
  14. vertical: 16,
  15. ),
  16. child: Row(
  17. children: <Widget>[
  18. Expanded(
  19. child: RichText(
  20. text: TextSpan(children: getStyledTexts(context)),
  21. ),
  22. )
  23. ],
  24. )),
  25. onTap: onTap,
  26. ),
  27. );
  28. }
  29. List<TextSpan> getStyledTexts(BuildContext context) {
  30. final List<TextSpan> result = [];
  31. String startText =
  32. autoCompleteItem.text.substring(0, autoCompleteItem.offset);
  33. if (startText.isNotEmpty) {
  34. result.add(
  35. TextSpan(
  36. text: startText,
  37. style: TextStyle(
  38. color: Colors.grey,
  39. fontSize: 15,
  40. ),
  41. ),
  42. );
  43. }
  44. String boldText = autoCompleteItem.text.substring(autoCompleteItem.offset,
  45. autoCompleteItem.offset + autoCompleteItem.length);
  46. result.add(TextSpan(
  47. text: boldText,
  48. style: TextStyle(
  49. color: Colors.black,
  50. fontSize: 15,
  51. ),
  52. ));
  53. String remainingText = this
  54. .autoCompleteItem
  55. .text
  56. .substring(autoCompleteItem.offset + autoCompleteItem.length);
  57. result.add(
  58. TextSpan(
  59. text: remainingText,
  60. style: TextStyle(
  61. color: Colors.grey,
  62. fontSize: 15,
  63. ),
  64. ),
  65. );
  66. return result;
  67. }
  68. }