From 57e5c36fe8af79f7bf7ce7e5d9f917039aa86b10 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 1 Jun 2022 15:28:54 +0800 Subject: [PATCH] chore: config toast --- .../workspace/presentation/home/toast.dart | 37 ++++++++++++ .../widgets/float_bubble/question_bubble.dart | 60 +++---------------- 2 files changed, 46 insertions(+), 51 deletions(-) create mode 100644 frontend/app_flowy/lib/workspace/presentation/home/toast.dart diff --git a/frontend/app_flowy/lib/workspace/presentation/home/toast.dart b/frontend/app_flowy/lib/workspace/presentation/home/toast.dart new file mode 100644 index 0000000000..28241c0ec4 --- /dev/null +++ b/frontend/app_flowy/lib/workspace/presentation/home/toast.dart @@ -0,0 +1,37 @@ +import 'package:app_flowy/startup/startup.dart'; +import 'package:flowy_infra_ui/style_widget/text.dart'; +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +class FlowyMessageToast extends StatelessWidget { + final String message; + const FlowyMessageToast({required this.message, Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), + child: FlowyText.medium(message, color: Colors.white), + ), + decoration: const BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(4)), + color: Colors.black, + ), + ); + } +} + +void initToastWithContext(BuildContext context) { + getIt().init(context); +} + +void showMessageToast(String message) { + final child = FlowyMessageToast(message: message); + + getIt().showToast( + child: child, + gravity: ToastGravity.BOTTOM, + toastDuration: const Duration(seconds: 3), + ); +} diff --git a/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart b/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart index 8fecbc9489..6cc150489c 100644 --- a/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart +++ b/frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart @@ -1,5 +1,5 @@ -import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/startup/tasks/rust_sdk.dart'; +import 'package:app_flowy/workspace/presentation/home/toast.dart'; import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra/theme.dart'; @@ -16,7 +16,6 @@ import 'package:package_info_plus/package_info_plus.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; import 'package:device_info_plus/device_info_plus.dart'; -import 'package:fluttertoast/fluttertoast.dart'; class QuestionBubble extends StatelessWidget { const QuestionBubble({Key? key}) : super(key: key); @@ -46,7 +45,7 @@ class QuestionBubble extends StatelessWidget { _launchURL("https://discord.gg/9Q2xaN37tV"); break; case BubbleAction.debug: - const _DebugToast().show(); + _DebugToast().show(); break; } }); @@ -71,55 +70,14 @@ class QuestionBubble extends StatelessWidget { } } -class _DebugToast extends StatelessWidget { - const _DebugToast({Key? key}) : super(key: key); +class _DebugToast { + void show() async { + var debugInfo = ""; + debugInfo += await _getDeviceInfo(); + debugInfo += await _getDocumentPath(); + Clipboard.setData(ClipboardData(text: debugInfo)); - @override - Widget build(BuildContext context) { - return FutureBuilder( - future: Future(() async { - var debugInfo = ""; - debugInfo += await _getDeviceInfo(); - debugInfo += await _getDocumentPath(); - - Clipboard.setData(ClipboardData(text: debugInfo)); - }), - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasError) { - return _done(context, Text("Error: ${snapshot.error}")); - } else { - return _done(context, null); - } - } else { - return const CircularProgressIndicator(); - } - }, - ); - } - - Widget _done(BuildContext context, Widget? error) { - final theme = context.watch(); - return Container( - padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), - decoration: BoxDecoration(borderRadius: BorderRadius.circular(25.0), color: theme.main1), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.check), - const SizedBox(width: 12.0), - (error == null) ? Text(LocaleKeys.questionBubble_debug_success.tr()) : error - ], - ), - ); - } - - void show() { - getIt().showToast( - child: this, - gravity: ToastGravity.BOTTOM, - toastDuration: const Duration(seconds: 3), - ); + showMessageToast(LocaleKeys.questionBubble_debug_success.tr()); } Future _getDeviceInfo() async {