Skip to content

Commit 57e5c36

Browse files
committed
chore: config toast
1 parent 1036521 commit 57e5c36

File tree

2 files changed

+46
-51
lines changed

2 files changed

+46
-51
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:app_flowy/startup/startup.dart';
2+
import 'package:flowy_infra_ui/style_widget/text.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:fluttertoast/fluttertoast.dart';
5+
6+
class FlowyMessageToast extends StatelessWidget {
7+
final String message;
8+
const FlowyMessageToast({required this.message, Key? key}) : super(key: key);
9+
10+
@override
11+
Widget build(BuildContext context) {
12+
return Container(
13+
child: Padding(
14+
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
15+
child: FlowyText.medium(message, color: Colors.white),
16+
),
17+
decoration: const BoxDecoration(
18+
borderRadius: BorderRadius.all(Radius.circular(4)),
19+
color: Colors.black,
20+
),
21+
);
22+
}
23+
}
24+
25+
void initToastWithContext(BuildContext context) {
26+
getIt<FToast>().init(context);
27+
}
28+
29+
void showMessageToast(String message) {
30+
final child = FlowyMessageToast(message: message);
31+
32+
getIt<FToast>().showToast(
33+
child: child,
34+
gravity: ToastGravity.BOTTOM,
35+
toastDuration: const Duration(seconds: 3),
36+
);
37+
}

frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import 'package:app_flowy/startup/startup.dart';
21
import 'package:app_flowy/startup/tasks/rust_sdk.dart';
2+
import 'package:app_flowy/workspace/presentation/home/toast.dart';
33
import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart';
44
import 'package:easy_localization/easy_localization.dart';
55
import 'package:flowy_infra/theme.dart';
@@ -16,7 +16,6 @@ import 'package:package_info_plus/package_info_plus.dart';
1616
import 'package:url_launcher/url_launcher.dart';
1717
import 'package:app_flowy/generated/locale_keys.g.dart';
1818
import 'package:device_info_plus/device_info_plus.dart';
19-
import 'package:fluttertoast/fluttertoast.dart';
2019

2120
class QuestionBubble extends StatelessWidget {
2221
const QuestionBubble({Key? key}) : super(key: key);
@@ -46,7 +45,7 @@ class QuestionBubble extends StatelessWidget {
4645
_launchURL("https://discord.gg/9Q2xaN37tV");
4746
break;
4847
case BubbleAction.debug:
49-
const _DebugToast().show();
48+
_DebugToast().show();
5049
break;
5150
}
5251
});
@@ -71,55 +70,14 @@ class QuestionBubble extends StatelessWidget {
7170
}
7271
}
7372

74-
class _DebugToast extends StatelessWidget {
75-
const _DebugToast({Key? key}) : super(key: key);
73+
class _DebugToast {
74+
void show() async {
75+
var debugInfo = "";
76+
debugInfo += await _getDeviceInfo();
77+
debugInfo += await _getDocumentPath();
78+
Clipboard.setData(ClipboardData(text: debugInfo));
7679

77-
@override
78-
Widget build(BuildContext context) {
79-
return FutureBuilder(
80-
future: Future(() async {
81-
var debugInfo = "";
82-
debugInfo += await _getDeviceInfo();
83-
debugInfo += await _getDocumentPath();
84-
85-
Clipboard.setData(ClipboardData(text: debugInfo));
86-
}),
87-
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
88-
if (snapshot.connectionState == ConnectionState.done) {
89-
if (snapshot.hasError) {
90-
return _done(context, Text("Error: ${snapshot.error}"));
91-
} else {
92-
return _done(context, null);
93-
}
94-
} else {
95-
return const CircularProgressIndicator();
96-
}
97-
},
98-
);
99-
}
100-
101-
Widget _done(BuildContext context, Widget? error) {
102-
final theme = context.watch<AppTheme>();
103-
return Container(
104-
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
105-
decoration: BoxDecoration(borderRadius: BorderRadius.circular(25.0), color: theme.main1),
106-
child: Row(
107-
mainAxisSize: MainAxisSize.min,
108-
children: [
109-
const Icon(Icons.check),
110-
const SizedBox(width: 12.0),
111-
(error == null) ? Text(LocaleKeys.questionBubble_debug_success.tr()) : error
112-
],
113-
),
114-
);
115-
}
116-
117-
void show() {
118-
getIt<FToast>().showToast(
119-
child: this,
120-
gravity: ToastGravity.BOTTOM,
121-
toastDuration: const Duration(seconds: 3),
122-
);
80+
showMessageToast(LocaleKeys.questionBubble_debug_success.tr());
12381
}
12482

12583
Future<String> _getDeviceInfo() async {

0 commit comments

Comments
 (0)