An open-source cross-platform alternative to AirDrop
feat: add slideshow for the info text
Tien Do Namc2c09704ec30
diff --git a/assets/i18n/strings.i18n.json b/assets/i18n/strings.i18n.jsonindex bff3f122..74457545 100644--- a/assets/i18n/strings.i18n.json+++ b/assets/i18n/strings.i18n.json@@ -51,7 +51,7 @@"media": "Media","text": "Text"},- "shareIntentInfo": "You can also use the native \"Share\" feature to select files more easily.",+ "shareIntentInfo": "You can also use the \"Share\" feature of your mobile device to select files more easily.","nearbyDevices": "Nearby devices","thisDevice": "This Device","scan": "Look for devices",diff --git a/assets/i18n/strings_de.i18n.json b/assets/i18n/strings_de.i18n.jsonindex 9f3ab37e..2a914267 100644--- a/assets/i18n/strings_de.i18n.json+++ b/assets/i18n/strings_de.i18n.json@@ -51,7 +51,7 @@"media": "Medien","text": "Text"},- "shareIntentInfo": "Du kannst auch die native \"Teilen\"-Funktion nutzen, um Dateien einfacher auszuwählen.",+ "shareIntentInfo": "Du kannst auch die \"Teilen\"-Funktion deines mobilen Geräts nutzen, um Dateien einfacher auszuwählen.","nearbyDevices": "Geräte in der Nähe","thisDevice": "Dieses Gerät","scan": "Geräte suchen",diff --git a/lib/pages/tabs/send_tab.dart b/lib/pages/tabs/send_tab.dartindex e1b60872..7ca73552 100644--- a/lib/pages/tabs/send_tab.dart+++ b/lib/pages/tabs/send_tab.dart@@ -13,6 +13,7 @@ import 'package:localsend_app/provider/settings_provider.dart';import 'package:localsend_app/util/file_picker.dart';import 'package:localsend_app/util/file_size_helper.dart';import 'package:localsend_app/util/platform_check.dart';+import 'package:localsend_app/widget/opacity_slideshow.dart';import 'package:localsend_app/widget/big_button.dart';import 'package:localsend_app/widget/dialogs/add_file_dialog.dart';import 'package:localsend_app/widget/dialogs/address_input_dialog.dart';@@ -60,8 +61,7 @@ class _SendTabState extends ConsumerState<SendTab> {final nearbyDevicesState = ref.watch(nearbyDevicesProvider);final addOptions = [FilePickerOption.file,- if (checkPlatformWithGallery())- FilePickerOption.media,+ if (checkPlatformWithGallery()) FilePickerOption.media,FilePickerOption.text,];@@ -226,9 +226,9 @@ class _SendTabState extends ConsumerState<SendTab> {);if (device != null && mounted) {ref.read(sendProvider.notifier).startSession(- target: device,- files: files,- );+ target: device,+ files: files,+ );}},child: const Icon(Icons.ads_click),@@ -295,7 +295,7 @@ class _SendTabState extends ConsumerState<SendTab> {final files = ref.read(selectedFilesProvider);if (files.isEmpty) {context.pushBottomSheet(() => const NoFilesDialog());- return;+ return;}ref.read(sendProvider.notifier).startSession(@@ -308,12 +308,14 @@ class _SendTabState extends ConsumerState<SendTab> {);}),const SizedBox(height: 20),- if (checkPlatformCanReceiveShareIntent())- Padding(- padding: const EdgeInsets.only(bottom: 10),- child: Text(t.sendTab.shareIntentInfo, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),- ),- Text(t.sendTab.help, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),+ OpacitySlideshow(+ durationMillis: 7000,+ children: [+ Text(t.sendTab.help, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),+ if (checkPlatformCanReceiveShareIntent())+ Text(t.sendTab.shareIntentInfo, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),+ ],+ ),const SizedBox(height: 50),],);diff --git a/lib/widget/opacity_slideshow.dart b/lib/widget/opacity_slideshow.dartnew file mode 100644index 00000000..1ddbd341--- /dev/null+++ b/lib/widget/opacity_slideshow.dart@@ -0,0 +1,65 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:localsend_app/util/sleep.dart';++/// A slideshow of widgets using [AnimatedOpacity] as transition.+class OpacitySlideshow extends StatefulWidget {+ final List<Widget> children;+ final int durationMillis;+ final int switchDurationMillis;++ const OpacitySlideshow({+ required this.children,+ required this.durationMillis,+ this.switchDurationMillis = 300,+ super.key,+ });++ @override+ State<OpacitySlideshow> createState() => _OpacitySlideshowState();+}++class _OpacitySlideshowState extends State<OpacitySlideshow> {+ Timer? _timer;+ int _index = 0;+ double _opacity = 1;++ @override+ void initState() {+ super.initState();+ if (widget.children.length > 1) {+ _startTimer();+ }+ }++ @override+ void dispose() {+ super.dispose();+ _timer?.cancel();+ }++ void _startTimer() {+ _timer = Timer.periodic(Duration(milliseconds: widget.durationMillis), (_) async {+ if (!mounted) return;+ setState(() {+ _opacity = 0;+ });+ await sleepAsync(widget.switchDurationMillis);+ if (!mounted) return;+ setState(() {+ _index = (_index + 1) % widget.children.length;+ _opacity = 1;+ });+ });+ }++ @override+ Widget build(BuildContext context) {+ return AnimatedOpacity(+ opacity: _opacity,+ duration: Duration(milliseconds: widget.switchDurationMillis),+ child: widget.children[_index],+ );+ }+}