mind_map_index.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_slidable/flutter_slidable.dart';
  3. import 'package:get/get.dart' as my_get;
  4. import '../../../common/api/index.dart';
  5. import '../../../common/models/index.dart';
  6. import '../../../common/routers/index.dart';
  7. import '../../../common/style/index.dart';
  8. import '../../../common/utils/index.dart';
  9. import '../../../common/values/index.dart';
  10. import '../../../common/widgets/index.dart';
  11. class MindMapHomePage extends StatefulWidget {
  12. const MindMapHomePage({Key? key}) : super(key: key);
  13. @override
  14. _MindMapHomePageState createState() => _MindMapHomePageState();
  15. }
  16. class _MindMapHomePageState extends State<MindMapHomePage>
  17. with SingleTickerProviderStateMixin {
  18. final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
  19. final ScrollController _scrollController = ScrollController(); //listview的控制器
  20. TextEditingController? newFolderEditingController;
  21. AnimationController? animationController;
  22. Animation<double>? animation;
  23. final List<MindMap> _datas = [];
  24. final List<MindFolder> _trees = [];
  25. bool _isFirstLoading = true;
  26. String _folderName = 'mindmap_root_folder'.tr;
  27. String _folderId = 'root';
  28. String _lastPageId = O2.o2DefaultPageFirstKey;
  29. String _title = "app_name_mindMap".tr;
  30. @override
  31. void initState() {
  32. super.initState();
  33. _title = my_get.Get.parameters['displayName'] ?? "app_name_mindMap".tr;
  34. newFolderEditingController = TextEditingController();
  35. animationController = AnimationController(
  36. duration: const Duration(milliseconds: 300), vsync: this);
  37. animation = Tween<double>(begin: 64, end: 400).animate(animationController!)
  38. ..addListener(() {
  39. setState(() {});
  40. });
  41. _getFolderTree();
  42. _getData();
  43. _scrollController.addListener(() {
  44. if (_scrollController.position.pixels ==
  45. _scrollController.position.maxScrollExtent) {
  46. _getMore();
  47. }
  48. });
  49. }
  50. @override
  51. void dispose() {
  52. animationController?.dispose();
  53. super.dispose();
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. return Scaffold(
  58. key: _scaffoldKey,
  59. appBar: AppBar(title: Text(_title)),
  60. body: _buildBody(),
  61. floatingActionButtonLocation: const MindMapFloatingActionButtonLocation(),
  62. floatingActionButton: FloatingActionButton(
  63. onPressed: _showAddMenu,
  64. tooltip: 'mindmap_create_btn_name'.tr,
  65. backgroundColor: Theme.of(context).primaryColor,
  66. child: const Icon(Icons.add, color: Colors.white),
  67. ), // This trailing comma makes auto-formatting nicer for build methods.
  68. );
  69. }
  70. void _getFolderTree() async {
  71. _trees.clear();
  72. final list = await MindMapService.to.myFolderTree();
  73. if (list != null) {
  74. //查询到tree转化成list
  75. Map<String, dynamic> json = {};
  76. json['name'] = 'mindmap_root_folder'.tr;
  77. json['id'] = 'root';
  78. MindFolder root = MindFolder.fromJson(json);
  79. root.level = 1;
  80. _trees.add(root);
  81. _recursionTree(list, 2);
  82. // 刷新选中目录的名称
  83. for (var tree in _trees) {
  84. if (tree.id == _folderId) {
  85. _folderName = tree.name ?? 'mindmap_root_folder'.tr;
  86. }
  87. }
  88. setState(() {});
  89. }
  90. }
  91. void _recursionTree(List<MindFolder> children, int level) {
  92. if (children.isEmpty) {
  93. return;
  94. }
  95. for (var tree in children) {
  96. tree.level = level;
  97. _trees.add(tree);
  98. if (tree.children != null && tree.children!.isNotEmpty) {
  99. _recursionTree(tree.children!, level + 1);
  100. }
  101. }
  102. }
  103. void _getData() {
  104. _lastPageId = O2.o2DefaultPageFirstKey;
  105. _datas.clear();
  106. _fetchData();
  107. }
  108. void _getMore() {
  109. if (_datas.isNotEmpty) {
  110. _lastPageId = _datas.last.id ?? O2.o2DefaultPageFirstKey;
  111. _fetchData();
  112. } else {
  113. OLogger.d('没有更多数据了。。。。。。。。。。');
  114. }
  115. }
  116. void _fetchData() async {
  117. final list = await MindMapService.to.mindFilterByPage(_lastPageId, _folderId);
  118. if (list != null && list.isNotEmpty) {
  119. _datas.addAll(list);
  120. }
  121. setState(() {
  122. _isFirstLoading = false;
  123. });
  124. // .then((list) {
  125. // if (list != null && list.isNotEmpty) {
  126. // _datas.addAll(list);
  127. // }
  128. // setState(() {
  129. // _isFirstLoading = false;
  130. // });
  131. // }).catchError((error) {
  132. // print(error);
  133. // setState(() {
  134. // _isFirstLoading = false;
  135. // });
  136. // _showErrorSnap('获取数据异常!');
  137. // });
  138. }
  139. void _changeFolder(int index) {
  140. _folderId = _trees[index].id!;
  141. _folderName = _trees[index].name!;
  142. _getData();
  143. }
  144. void _newOrEditFolder(String parentId, String? id) async {
  145. var folderName = newFolderEditingController?.text;
  146. if (folderName == null || folderName.trim().isEmpty) {
  147. _showErrorSnap('mindmap_msg_name_not_empty'.tr);
  148. } else {
  149. Loading.show();
  150. final d =
  151. await MindMapService.to.saveMindFolder(folderName, parentId, id: id);
  152. if (d != null) {
  153. Loading.dismiss();
  154. _getFolderTree();
  155. }
  156. // .then((id) {
  157. // }).catchError((error) {
  158. // print(error);
  159. // Loading.complete(context);
  160. // _showErrorSnap(id == null ? '新建目录失败!' : '修改目录失败!');
  161. // });
  162. }
  163. }
  164. ///
  165. /// 删除目录
  166. /// 先判断是否有子目录,然后查询是否有文件 ,全都没有才能删除
  167. ///
  168. void _deleteFolderValidate(int index) async {
  169. MindFolder deleteFolder = _trees[index];
  170. bool hasSubFolder = true;
  171. if (index + 1 < _trees.length) {
  172. MindFolder next = _trees[index + 1];
  173. if (deleteFolder.level! < next.level!) {
  174. //是子目录
  175. _showErrorSnap('mindmap_msg_have_sub_folder'.tr);
  176. } else {
  177. hasSubFolder = false;
  178. }
  179. } else {
  180. hasSubFolder = false;
  181. }
  182. if (!hasSubFolder) {
  183. List<MindMap>? list = await MindMapService.to
  184. .mindFilterByPage(O2.o2DefaultPageFirstKey, deleteFolder.id!);
  185. if (list != null && list.isNotEmpty) {
  186. _showErrorSnap('mindmap_msg_have_map_in_folder'.tr);
  187. } else {
  188. O2UI.showConfirm(my_get.Get.context, 'mindmap_msg_confirm_delete_folder'.tr, okPressed: () {
  189. _deleteFolder(index);
  190. });
  191. // O2Dialogs.showConfirmDialog(message: '确定要删除这个目录?', context: context)
  192. // .then((result) {
  193. // if (result == O2DialogAction.positive) {
  194. // _deleteFolder(index);
  195. // }
  196. // });
  197. }
  198. }
  199. }
  200. void _deleteFolder(int index) async {
  201. MindFolder deleteFolder = _trees[index];
  202. bool result = await MindMapService.to.deleteMindFolder(deleteFolder.id!);
  203. if (result) {
  204. if (_folderId == deleteFolder.id) {
  205. _changeFolder(0);
  206. }
  207. setState(() {
  208. _trees.removeAt(index);
  209. });
  210. }
  211. }
  212. ///新建脑图
  213. void _newMindMap() async {
  214. var mindName = newFolderEditingController?.text;
  215. if (mindName == null || mindName.trim().isEmpty) {
  216. _showErrorSnap('mindmap_msg_map_name_not_empty'.tr);
  217. } else {
  218. Loading.show();
  219. Node node = Node(data: NodeData(text: mindName), children: []);
  220. Map<String, dynamic> dataJson = {};
  221. dataJson['root'] = node.toJson();
  222. dataJson['template'] = 'default';
  223. dataJson['theme'] = 'fresh-blue';
  224. MindMapData data = MindMapData.fromJson(dataJson);
  225. Map<String, dynamic> mindJson = {};
  226. mindJson['name'] = mindName;
  227. mindJson['folderId'] = _folderId;
  228. mindJson['fileVersion'] = 0;
  229. MindMap map = MindMap.fromJson(mindJson);
  230. final id = await MindMapService.to.saveMindMap(map, data);
  231. if (id != null && id.isNotEmpty) {
  232. Loading.dismiss();
  233. map.id = id;
  234. _datas.add(map);
  235. setState(() {});
  236. _gotoMindMapView(_datas.length - 1);
  237. }
  238. // .then((id) {
  239. // if (id.isNotEmpty) {
  240. // }
  241. // }).catchError((error) {
  242. // print('新建脑图异常$error');
  243. // Loading.complete(context);
  244. // _showErrorSnap('新建脑图失败!');
  245. // });
  246. }
  247. }
  248. void _renameMindMap(MindMap map) async {
  249. newFolderEditingController?.text = map.name ?? '';
  250. final result = await O2UI.showCustomDialog(
  251. context,
  252. 'mindmap_rename_map'.tr,
  253. TextField(
  254. controller: newFolderEditingController,
  255. autofocus: true,
  256. decoration:
  257. InputDecoration(labelText: 'mindmap_name_label'.tr, hintText: 'mindmap_msg_enter_map_name'.tr),
  258. ));
  259. if (result != null && result == O2DialogAction.positive) {
  260. _renameMindMap2Remote(map);
  261. }
  262. // O2Dialogs.showCustomDialog(
  263. // context: context,
  264. // title: '重命名脑图',
  265. // content: TextField(
  266. // controller: newFolderEditingController,
  267. // autofocus: true,
  268. // decoration:
  269. // const InputDecoration(labelText: '名称', hintText: '请输入脑图名称'),
  270. // )).then((action) {
  271. // if (action == O2DialogAction.positive) {
  272. // _renameMindMap2Remote(map);
  273. // }
  274. // });
  275. }
  276. ///新建脑图
  277. void _renameMindMap2Remote(MindMap map) async {
  278. var mindName = newFolderEditingController?.text;
  279. if (mindName == null || mindName.trim().isEmpty) {
  280. _showErrorSnap('mindmap_msg_map_name_not_empty'.tr);
  281. } else {
  282. map.name = mindName;
  283. var allMindMapData =
  284. await MindMapService.to.mindMap(map.id!); //要重新get一下 不然content没有内容
  285. if (allMindMapData != null) {
  286. allMindMapData.name = mindName;
  287. final id = await MindMapService.to.renameMindMap(allMindMapData);
  288. if (id != null) {
  289. setState(() {
  290. OLogger.d('更新了脑图名称。。。。。。。。');
  291. });
  292. }
  293. }
  294. // MindMapService.to.renameMindMap(allMindMapData).then((id) {
  295. // if (id.isNotEmpty) {
  296. // setState(() {
  297. // print('更新了脑图名称。。。。。。。。');
  298. // });
  299. // }
  300. // }).catchError((error) {
  301. // print('更新脑图异常$error');
  302. // _showErrorSnap('更新脑图失败!');
  303. // });
  304. }
  305. }
  306. void _deleteMindMap(MindMap map) {
  307. O2UI.showConfirm(context, 'mindmap_msg_confirm_delete_map'.trArgs([map.name??'']), okPressed: () {
  308. _deleteMindMap2Server(map);
  309. });
  310. // O2Dialogs.showConfirmDialog(
  311. // message: '确定要删除这个脑图,名称:【${map.name}】?', context: context)
  312. // .then((result) {
  313. // if (result == O2DialogAction.positive) {
  314. // MindMapService.to.deleteMindMap(map.id!).then((result) {
  315. // if (!result) {
  316. // print('删除失败');
  317. // }
  318. // _getData();
  319. // }).catchError((error) {
  320. // print('删除脑图出错,$error');
  321. // _showErrorSnap('删除脑图出错!');
  322. // });
  323. // }
  324. // });
  325. }
  326. void _deleteMindMap2Server(MindMap map) async {
  327. final result = await MindMapService.to.deleteMindMap(map.id!);
  328. if (!result) {
  329. OLogger.d('删除失败');
  330. }
  331. _getData();
  332. }
  333. void _gotoMindMapView(int index) async {
  334. OLogger.d('点了第$index行。。。。。。。打开脑图编辑器');
  335. // await AppRouterManager.instance.router?.navigateTo(context, '/mindMap/${_datas[index].id}');
  336. await my_get.Get.toNamed(O2OARoutes.appMindMapView,
  337. arguments: {'mapId': _datas[index].id});
  338. OLogger.d('返回了。。。。刷新数据');
  339. _getData();
  340. }
  341. Widget _buildBody() {
  342. if (_isFirstLoading) {
  343. return const Center(child: CircularProgressIndicator());
  344. } else {
  345. return Column(
  346. children: <Widget>[
  347. Expanded(
  348. child: _datas.isNotEmpty ? _gridView() : _emptyDataView(),
  349. ),
  350. _bottomFolderBar()
  351. ],
  352. );
  353. }
  354. }
  355. //grid 列表
  356. Widget _gridView() {
  357. return Padding(
  358. padding: const EdgeInsets.all(5),
  359. child: GridView.builder(
  360. controller: _scrollController,
  361. itemCount: _datas.length,
  362. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  363. crossAxisCount: 2, mainAxisSpacing: 5, crossAxisSpacing: 5),
  364. itemBuilder: _gridItemView));
  365. }
  366. Widget _gridItemView(BuildContext context, int index) {
  367. MindMap data = _datas[index];
  368. final url = O2ApiManager.instance.getFileURL(data.icon);
  369. return InkWell(
  370. child: GridTile(
  371. footer: Container(
  372. height: 40,
  373. decoration: BoxDecoration(
  374. border: Border.all(color: AppColor.dividerColor),
  375. color: Theme.of(context).scaffoldBackgroundColor),
  376. child: Row(
  377. crossAxisAlignment: CrossAxisAlignment.center,
  378. mainAxisAlignment: MainAxisAlignment.center,
  379. children: <Widget>[
  380. Expanded(
  381. flex: 1,
  382. child: Padding(
  383. padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
  384. child: Text(data.name ?? '',
  385. style: Theme.of(context).textTheme.bodyLarge),
  386. ),
  387. ),
  388. IconButton(
  389. icon: const Icon(Icons.more_vert),
  390. onPressed: () => _showMindMapOperationMenu(data),
  391. )
  392. ],
  393. ),
  394. ),
  395. child: Container(
  396. height: 144,
  397. color: AppColor.o2Dark,
  398. child: Center(
  399. child: url.isEmpty
  400. ? const AssetsImageView('unknow.png', width: 48, height: 48)
  401. : FadeInImage.assetNetwork(
  402. placeholder: 'assets/images/unknow.png', image: url),
  403. )),
  404. ),
  405. onTap: () {
  406. _gotoMindMapView(index);
  407. },
  408. );
  409. }
  410. // //列表
  411. // Widget _listView() {
  412. // return ListView.separated(
  413. // controller: _scrollController,
  414. // itemBuilder: _itemView,
  415. // separatorBuilder: _separatorView,
  416. // itemCount: _datas.length);
  417. // }
  418. //列表项外框和点击事件
  419. // Widget _itemView(BuildContext context, int index) {
  420. // return InkWell(
  421. // child: _slideRow(index, _datas[index]),
  422. // onTap: () {
  423. // _gotoMindMapView(index);
  424. // },
  425. // );
  426. // }
  427. //列表项滑动控件
  428. // Widget _slideRow(int index, MindMap data) {
  429. // return Slidable(
  430. // // The end action pane is the one at the right or the bottom side.
  431. // endActionPane: ActionPane(
  432. // motion: const ScrollMotion(),
  433. // children: [
  434. // SlidableAction(
  435. // onPressed: (_) {
  436. // _deleteMindMap(_datas[index]);
  437. // },
  438. // backgroundColor: Colors.red,
  439. // foregroundColor: Colors.white,
  440. // icon: Icons.delete,
  441. // label: '删除',
  442. // ),
  443. // ],
  444. // ),
  445. // child: _rowContentView(data),
  446. // );
  447. // }
  448. //列表项内容
  449. // Widget _rowContentView(MindMap data) {
  450. // final url = O2ApiManager.instance.getFileURL(data.icon);
  451. // return ListTile(
  452. // leading: Container(
  453. // width: 48,
  454. // height: 48,
  455. // color: AppColor.o2Dark,
  456. // child: url.isEmpty
  457. // ? const AssetsImageView('unknow.png', width: 48, height: 48)
  458. // : FadeInImage.assetNetwork(
  459. // placeholder: 'assets/images/unknow.png',
  460. // image: url,
  461. // width: 48,
  462. // height: 48,
  463. // ),
  464. // ),
  465. // title: Text(data.name ?? ''),
  466. // subtitle: Text('版本:${data.fileVersion}'),
  467. // trailing: Text(_timeFormat(data.updateTime),
  468. // style: Theme.of(context).textTheme.bodySmall),
  469. // );
  470. // }
  471. ///
  472. /// @param time 2019-02-11 12:20:00
  473. // String _timeFormat(String? time) {
  474. // if (time != null && time.isNotEmpty && time.length > 16) {
  475. // var year = time.substring(0, 4);
  476. // if (DateTime.now().year == int.parse(year)) {
  477. // return time.substring(5, 16);
  478. // } else {
  479. // return time.substring(0, 16);
  480. // }
  481. // } else {
  482. // return "";
  483. // }
  484. // }
  485. //分割线
  486. // Widget _separatorView(BuildContext context, int index) {
  487. // return const Divider(height: 1);
  488. // }
  489. // 没有数据的时候显示的文字
  490. Widget _emptyDataView() {
  491. return Center(
  492. child: Text('empty_data'.tr, style: Theme.of(context).textTheme.bodySmall));
  493. }
  494. // 底部 文件夹 栏
  495. Widget _bottomFolderBar() {
  496. var screenWidth = MediaQuery.of(context).size.width;
  497. return SizedBox(
  498. height: animation!.value,
  499. child: Stack(
  500. children: <Widget>[
  501. Positioned(
  502. left: 0,
  503. top: 0,
  504. width: screenWidth,
  505. height: 400,
  506. child: Column(
  507. children: <Widget>[
  508. _bottomFolderBarHeader(),
  509. Expanded(
  510. child: Container(
  511. child: _bottomFolderListView(),
  512. ),
  513. )
  514. ],
  515. ))
  516. ],
  517. ));
  518. }
  519. Widget _bottomFolderBarHeader() {
  520. return InkWell(
  521. onTap: () {
  522. if (animation!.value > 64) {
  523. animationController?.reverse();
  524. } else {
  525. animationController?.forward();
  526. }
  527. },
  528. child: Container(
  529. padding: const EdgeInsets.all(16),
  530. color: Theme.of(context).colorScheme.background,
  531. child: Row(
  532. children: <Widget>[
  533. const Icon(Icons.folder, size: 32),
  534. Expanded(
  535. child: Align(
  536. alignment: Alignment.center,
  537. child: Text(_folderName,
  538. style: Theme.of(context).textTheme.bodyLarge),
  539. ),
  540. ),
  541. animation!.value > 64
  542. ? const Icon(Icons.arrow_drop_down, size: 32)
  543. : const Icon(Icons.arrow_drop_up, size: 32)
  544. ],
  545. ),
  546. ),
  547. );
  548. }
  549. Widget _bottomFolderListView() {
  550. return ListView.builder(
  551. itemBuilder: _folderItemView,
  552. itemCount: _trees.length,
  553. );
  554. }
  555. Widget _folderItemView(BuildContext context, int index) {
  556. final folder = _trees[index];
  557. return InkWell(
  558. onTap: () {
  559. _changeFolder(index);
  560. animationController?.reverse();
  561. },
  562. child: Slidable(
  563. endActionPane: ActionPane(
  564. motion: const ScrollMotion(),
  565. children: _folderSlideMenu(index),
  566. ),
  567. child: ListTile(
  568. contentPadding: EdgeInsets.only(left: 16.0 + ((folder.level ?? 0) * 8.0), right: 16),
  569. title: Text(folder.name ?? ''),
  570. selected: folder.id == _folderId,
  571. )),
  572. );
  573. }
  574. ///
  575. /// 目录列表横拉菜单
  576. ///
  577. List<Widget> _folderSlideMenu(int index) {
  578. if (index == 0) {
  579. return [];
  580. } else {
  581. return <Widget>[
  582. SlidableAction(
  583. onPressed: (_) {
  584. OLogger.d('删除目录。。。。。。。。');
  585. _deleteFolderValidate(index);
  586. },
  587. backgroundColor: Colors.red,
  588. foregroundColor: Colors.white,
  589. icon: Icons.delete,
  590. label: 'mindmap_delete_btn_name'.tr,
  591. ),
  592. SlidableAction(
  593. onPressed: (_) {
  594. OLogger.d('重命名目录。。。。。。。。');
  595. _showFolderDialog(_trees[index]);
  596. },
  597. backgroundColor: Colors.blue,
  598. foregroundColor: Colors.white,
  599. icon: Icons.edit,
  600. label: 'mindmap_rename_btn_name'.tr,
  601. )
  602. ];
  603. }
  604. }
  605. ///
  606. /// 底部弹出菜单 选择 新建脑图 新建文件夹
  607. ///
  608. void _showAddMenu() {
  609. O2UI.showBottomSheetWithCancel(context, <Widget>[
  610. ListTile(
  611. onTap: () {
  612. OLogger.d('新建脑图。。。。。。。。');
  613. Navigator.of(context).pop();
  614. _showNewMindMap();
  615. },
  616. leading: const Icon(Icons.add_box),
  617. title: Text('mindmap_create_map'.tr, style: Theme.of(context).textTheme.bodyMedium),
  618. ),
  619. ListTile(
  620. onTap: () {
  621. Navigator.of(context).pop();
  622. _showFolderDialog(null);
  623. },
  624. leading: const Icon(Icons.create_new_folder),
  625. title: Text('mindmap_create_folder'.tr, style: Theme.of(context).textTheme.bodyMedium),
  626. )
  627. ]);
  628. }
  629. void _showMindMapOperationMenu(MindMap data) {
  630. OLogger.d('显示菜单。。。${data.name}');
  631. O2UI.showBottomSheetWithCancel(context, <Widget>[
  632. ListTile(
  633. onTap: () {
  634. Navigator.of(context).pop();
  635. _renameMindMap(data);
  636. },
  637. leading: const Icon(Icons.edit),
  638. title: Text('mindmap_rename_btn_name'.tr, style: Theme.of(context).textTheme.bodyMedium),
  639. ),
  640. ListTile(
  641. onTap: () {
  642. Navigator.of(context).pop();
  643. _deleteMindMap(data);
  644. },
  645. leading: const Icon(Icons.delete_forever),
  646. title: Text('mindmap_delete_btn_name'.tr, style: Theme.of(context).textTheme.bodyMedium),
  647. )
  648. ]);
  649. }
  650. void _showErrorSnap(String message) {
  651. // O2SnackBars.showSnackBar(_scaffoldKey, message);
  652. Loading.toast(message);
  653. }
  654. ///
  655. /// 新建目录
  656. ///
  657. void _showFolderDialog(MindFolder? old) async {
  658. String title;
  659. String parentId;
  660. String? id;
  661. if (old != null) {
  662. newFolderEditingController?.text = old.name ?? '';
  663. title = 'mindmap_rename_btn_name'.tr;
  664. parentId = old.parentId!;
  665. id = old.id!;
  666. } else {
  667. newFolderEditingController?.text = '';
  668. title = 'mindmap_msg_create_under_foler'.trArgs([_folderName]);
  669. parentId = _folderId;
  670. id = null;
  671. }
  672. var result = await O2UI.showCustomDialog(
  673. context,
  674. title,
  675. TextField(
  676. controller: newFolderEditingController,
  677. autofocus: true,
  678. decoration:
  679. InputDecoration(labelText: 'mindmap_name_label'.tr, hintText: 'mindmap_msg_enter_folder_name'.tr),
  680. ));
  681. if (result != null && result == O2DialogAction.positive) {
  682. _newOrEditFolder(parentId, id);
  683. }
  684. // O2Dialogs.showCustomDialog(
  685. // context: context,
  686. // title: title,
  687. // content: TextField(
  688. // controller: newFolderEditingController,
  689. // autofocus: true,
  690. // decoration:
  691. // const InputDecoration(labelText: '名称', hintText: '请输入目录名称'),
  692. // )).then((action) {
  693. // if (action == O2DialogAction.positive) {
  694. // _newOrEditFolder(parentId, id);
  695. // }
  696. // });
  697. }
  698. ///
  699. /// 新建脑图Dialog
  700. ///
  701. void _showNewMindMap() async {
  702. newFolderEditingController?.text = '';
  703. var result = await O2UI.showCustomDialog(
  704. context,
  705. 'mindmap_msg_create_map_under_foler'.trArgs([_folderName]),
  706. TextField(
  707. controller: newFolderEditingController,
  708. autofocus: true,
  709. decoration:
  710. InputDecoration(labelText: 'mindmap_map_name_label'.tr, hintText: 'mindmap_msg_enter_map_name'.tr),
  711. ));
  712. if (result != null && result == O2DialogAction.positive) {
  713. _newMindMap();
  714. }
  715. // O2Dialogs.showCustomDialog(
  716. // context: context,
  717. // title: '在【$_folderName】下新建脑图',
  718. // content: TextField(
  719. // controller: newFolderEditingController,
  720. // autofocus: true,
  721. // decoration:
  722. // const InputDecoration(labelText: '脑图名称', hintText: '请输入脑图名称'),
  723. // )).then((action) {
  724. // if (action == O2DialogAction.positive) {
  725. // _newMindMap();
  726. // }
  727. // });
  728. }
  729. }