mind_map_hyperlink.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import 'package:flutter/material.dart';
  2. import '../models/mindmap/mind_node.dart';
  3. import 'final_widget.dart';
  4. class MindMapHyperlinkForm extends StatefulWidget {
  5. final String hyperlink;
  6. final String hyperlinkTitle;
  7. MindMapHyperlinkForm({required this.hyperlink, required this.hyperlinkTitle});
  8. @override
  9. State<StatefulWidget> createState() {
  10. return MindMapHyperlinkFormState();
  11. }
  12. }
  13. class MindMapHyperlinkFormState extends State<MindMapHyperlinkForm> {
  14. final GlobalKey<FormState> _formKey = GlobalKey();
  15. late String _link;
  16. late String _linkTitle;
  17. @override
  18. Widget build(BuildContext context) {
  19. _link = widget.hyperlink;
  20. _linkTitle = widget.hyperlinkTitle;
  21. return Scaffold(
  22. appBar: AppBar(
  23. title: const Text('链接'),
  24. ),
  25. body: Container(
  26. color: Colors.white,
  27. width: double.infinity,
  28. height: double.infinity,
  29. padding: const EdgeInsets.all(32.0),
  30. child: SingleChildScrollView(
  31. child: Form(
  32. key: _formKey,
  33. child: Column(children: <Widget>[
  34. TextFormField(
  35. initialValue: _link,
  36. maxLines: 1,
  37. autofocus: true,
  38. keyboardType: TextInputType.text,
  39. decoration: const InputDecoration(
  40. labelText: '链接地址',
  41. hintText: '必填:以 http(s):// 或 ftp(s):// 开头'),
  42. validator: (value) {
  43. if (value?.isEmpty == true) {
  44. return '链接地址不能为空!';
  45. }
  46. if (!value!.startsWith(RegExp(r"https?://")) &&
  47. !value.startsWith(RegExp(r"ftps?://"))) {
  48. return '链接地址格式不正确!';
  49. }
  50. return null;
  51. },
  52. onSaved: (value) => _link = value ?? ''),
  53. O2UI.divider,
  54. TextFormField(
  55. initialValue: _linkTitle,
  56. maxLines: 1,
  57. keyboardType: TextInputType.text,
  58. decoration: const InputDecoration(
  59. labelText: '链接文本', hintText: '选填'),
  60. onSaved: (value) => _linkTitle = value ?? ''),
  61. O2UI.divider,
  62. Row(
  63. mainAxisSize: MainAxisSize.min,
  64. children: <Widget>[
  65. Expanded(
  66. flex: 1,
  67. child: Align(
  68. alignment: Alignment.center,
  69. child: RaisedButton(
  70. child: const Text('取消'),
  71. onPressed: () {
  72. _close(null);
  73. },
  74. ),
  75. ),
  76. ),
  77. Expanded(
  78. flex: 1,
  79. child: Align(
  80. alignment: Alignment.center,
  81. child: RaisedButton(
  82. child: const Text('确定'),
  83. onPressed: () {
  84. if (_formKey.currentState?.validate() == true) {
  85. _formKey.currentState?.save();
  86. NodeData data = NodeData();
  87. data.hyperlink = _link;
  88. data.hyperlinkTitle = _linkTitle;
  89. _close(data);
  90. }
  91. },
  92. color: Colors.blue,
  93. textColor: Colors.white,
  94. )),
  95. ),
  96. ],
  97. )
  98. ]),
  99. ),
  100. )));
  101. }
  102. void _close(NodeData? data) {
  103. Navigator.pop(context, data);
  104. }
  105. }