An open-source cross-platform alternative to AirDrop
feat: responsive UI
Tien Do Nam951eb59125e3
diff --git a/lib/pages/about_page.dart b/lib/pages/about_page.dartindex bb81e6b5..dd04cb88 100644--- a/lib/pages/about_page.dart+++ b/lib/pages/about_page.dart@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';import 'package:localsend_app/gen/strings.g.dart';import 'package:localsend_app/pages/debug_page.dart';import 'package:localsend_app/widget/local_send_logo.dart';+import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:routerino/routerino.dart';import 'package:url_launcher/url_launcher.dart';@@ -28,7 +29,7 @@ class AboutPage extends StatelessWidget {appBar: AppBar(title: Text(t.aboutPage.title),),- body: ListView(+ body: ResponsiveListView(padding: const EdgeInsets.symmetric(horizontal: 15),children: [const SizedBox(height: 20),diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dartindex 2fbf4868..54f05513 100644--- a/lib/pages/home_page.dart+++ b/lib/pages/home_page.dart@@ -7,6 +7,9 @@ import 'package:localsend_app/pages/tabs/receive_tab.dart';import 'package:localsend_app/pages/tabs/send_tab.dart';import 'package:localsend_app/pages/tabs/settings_tab.dart';import 'package:localsend_app/provider/selected_files_provider.dart';+import 'package:localsend_app/theme.dart';+import 'package:localsend_app/widget/responsive_list_view.dart';+import 'package:responsive_builder/responsive_builder.dart';enum HomeTab {receive(Icons.wifi),@@ -74,49 +77,80 @@ class _HomePageState extends ConsumerState<HomePage> {},onDragDone: (event) {ref.read(selectedFilesProvider.notifier).addFiles(- files: event.files,- converter: CrossFileConverters.convertXFile,- );+ files: event.files,+ converter: CrossFileConverters.convertXFile,+ );_goToPage(HomeTab.send.index);},- child: Scaffold(- body: SafeArea(- child: Stack(- children: [- PageView(- controller: _pageController,- physics: const NeverScrollableScrollPhysics(),- children: const [- ReceiveTab(),- SendTab(),- SettingsTab(),+ child: ResponsiveBuilder(+ breakpoints: ResponsiveListView.defaultBreakpoints,+ builder: (context, sizingInformation) {+ return Scaffold(+ body: SafeArea(+ child: Row(+ children: [+ if (!sizingInformation.isMobile)+ NavigationRail(+ selectedIndex: _currentTab.index,+ onDestinationSelected: _goToPage,+ extended: sizingInformation.isDesktop,+ backgroundColor: Theme.of(context).cardColorWithElevation,+ leading: sizingInformation.isDesktop ? Column(+ children: const [+ SizedBox(height: 20),+ Text('LocalSend', style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold), textAlign: TextAlign.center,),+ SizedBox(height: 20),+ ],+ ) : null,+ destinations: HomeTab.values.map((tab) {+ return NavigationRailDestination(+ icon: Icon(tab.icon),+ label: Text(tab.label),+ );+ }).toList(),+ ),+ Expanded(+ child: Stack(+ children: [+ PageView(+ controller: _pageController,+ physics: const NeverScrollableScrollPhysics(),+ children: const [+ ReceiveTab(),+ SendTab(),+ SettingsTab(),+ ],+ ),+ if (_dragAndDropIndicator)+ Container(+ width: double.infinity,+ decoration: BoxDecoration(+ color: Theme.of(context).scaffoldBackgroundColor,+ ),+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ const Icon(Icons.file_download, size: 128),+ const SizedBox(height: 30),+ Text(t.sendTab.placeItems, style: Theme.of(context).textTheme.headline6),+ ],+ ),+ ),+ ],+ ),+ ),],),- if (_dragAndDropIndicator)- Container(- width: double.infinity,- decoration: BoxDecoration(- color: Theme.of(context).scaffoldBackgroundColor,- ),- child: Column(- mainAxisAlignment: MainAxisAlignment.center,- children: [- const Icon(Icons.file_download, size: 128),- const SizedBox(height: 30),- Text(t.sendTab.placeItems, style: Theme.of(context).textTheme.headline6),- ],- ),- ),- ],- ),- ),- bottomNavigationBar: NavigationBar(- selectedIndex: _currentTab.index,- onDestinationSelected: _goToPage,- destinations: HomeTab.values.map((tab) {- return NavigationDestination(icon: Icon(tab.icon), label: tab.label);- }).toList(),- ),+ ),+ bottomNavigationBar: sizingInformation.isMobile ? NavigationBar(+ selectedIndex: _currentTab.index,+ onDestinationSelected: _goToPage,+ destinations: HomeTab.values.map((tab) {+ return NavigationDestination(icon: Icon(tab.icon), label: tab.label);+ }).toList(),+ ) : null,+ );+ },),);}diff --git a/lib/pages/selected_files_page.dart b/lib/pages/selected_files_page.dartindex c7bd32c0..e208911b 100644--- a/lib/pages/selected_files_page.dart+++ b/lib/pages/selected_files_page.dart@@ -8,6 +8,7 @@ import 'package:localsend_app/model/file_type.dart';import 'package:localsend_app/provider/selected_files_provider.dart';import 'package:localsend_app/util/file_size_helper.dart';import 'package:localsend_app/widget/file_thumbnail.dart';+import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:routerino/routerino.dart';class SelectedFilesPage extends ConsumerWidget {@@ -21,7 +22,7 @@ class SelectedFilesPage extends ConsumerWidget {appBar: AppBar(title: Text(t.sendTab.selection.title),),- body: ListView(+ body: ResponsiveListView(padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),children: [Row(diff --git a/lib/pages/tabs/receive_tab.dart b/lib/pages/tabs/receive_tab.dartindex ce4c4fd2..c319544e 100644--- a/lib/pages/tabs/receive_tab.dart+++ b/lib/pages/tabs/receive_tab.dart@@ -7,6 +7,7 @@ import 'package:localsend_app/provider/network/server_provider.dart';import 'package:localsend_app/provider/settings_provider.dart';import 'package:localsend_app/util/ip_helper.dart';import 'package:localsend_app/widget/animations/initial_fade_transition.dart';+import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:localsend_app/widget/rotating_widget.dart';class ReceiveTab extends ConsumerStatefulWidget {@@ -29,102 +30,107 @@ class _ReceiveTagState extends ConsumerState<ReceiveTab> with AutomaticKeepAlivefinal settings = ref.watch(settingsProvider);final networkInfo = ref.watch(networkInfoProvider);final serverState = ref.watch(serverProvider);- return Padding(- padding: const EdgeInsets.symmetric(horizontal: 20),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- Expanded(- child: FittedBox(- fit: BoxFit.scaleDown,- child: Center(- child: Column(- mainAxisAlignment: MainAxisAlignment.center,- children: [- InitialFadeTransition(- duration: const Duration(milliseconds: 300),- delay: const Duration(milliseconds: 200),- child: RotatingWidget(- duration: const Duration(seconds: 15),- spinning: serverState != null,- child: SizedBox(- height: 200,- child: Assets.img.logo512.image(height: 200),+ return Center(+ child: ConstrainedBox(+ constraints: const BoxConstraints(maxWidth: ResponsiveListView.defaultMaxWidth),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 20),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Expanded(+ child: FittedBox(+ fit: BoxFit.scaleDown,+ child: Center(+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ InitialFadeTransition(+ duration: const Duration(milliseconds: 300),+ delay: const Duration(milliseconds: 200),+ child: RotatingWidget(+ duration: const Duration(seconds: 15),+ spinning: serverState != null,+ child: SizedBox(+ height: 200,+ child: Assets.img.logo512.image(height: 200),+ ),+ ),),- ),- ),- Text(serverState?.alias ?? settings.alias, style: const TextStyle(fontSize: 48)),- InitialFadeTransition(- duration: const Duration(milliseconds: 300),- delay: const Duration(milliseconds: 500),- child: Text(- serverState == null ? t.general.offline : '#${networkInfo?.localIp?.visualId ?? '?'}',- style: const TextStyle(fontSize: 24),- ),+ Text(serverState?.alias ?? settings.alias, style: const TextStyle(fontSize: 48)),+ InitialFadeTransition(+ duration: const Duration(milliseconds: 300),+ delay: const Duration(milliseconds: 500),+ child: Text(+ serverState == null ? t.general.offline : '#${networkInfo?.localIp?.visualId ?? '?'}',+ style: const TextStyle(fontSize: 24),+ ),+ ),+ ],),- ],+ ),),),- ),- ),- Center(- child: TextButton(- key: ValueKey('toggle-$_advanced'),- onPressed: () {- setState(() => _advanced = !_advanced);- },- child: Text(_advanced ? t.general.hide : t.general.advanced),- ),- ),- AnimatedCrossFade(- crossFadeState: _advanced ? CrossFadeState.showSecond : CrossFadeState.showFirst,- duration: const Duration(milliseconds: 200),- firstChild: Container(),- secondChild: Card(- child: Padding(- padding: const EdgeInsets.all(15),- child: Table(- columnWidths: const {- 0: IntrinsicColumnWidth(),- 1: IntrinsicColumnWidth(),- 2: FlexColumnWidth(),+ Center(+ child: TextButton(+ key: ValueKey('toggle-$_advanced'),+ onPressed: () {+ setState(() => _advanced = !_advanced);},- children: [- TableRow(- children: [- Text(t.receiveTab.infoBox.alias),- const SizedBox(width: 10),- Text(serverState?.alias ?? '-'),- ],- ),- TableRow(- children: [- Text(t.receiveTab.infoBox.ip),- const SizedBox(width: 10),- Text(networkInfo?.localIp ?? t.general.unknown),- ],- ),- TableRow(- children: [- Text(t.receiveTab.infoBox.port),- const SizedBox(width: 10),- Text(serverState?.port.toString() ?? '-'),- ],- ),- TableRow(+ child: Text(_advanced ? t.general.hide : t.general.advanced),+ ),+ ),+ AnimatedCrossFade(+ crossFadeState: _advanced ? CrossFadeState.showSecond : CrossFadeState.showFirst,+ duration: const Duration(milliseconds: 200),+ firstChild: Container(),+ secondChild: Card(+ child: Padding(+ padding: const EdgeInsets.all(15),+ child: Table(+ columnWidths: const {+ 0: IntrinsicColumnWidth(),+ 1: IntrinsicColumnWidth(),+ 2: FlexColumnWidth(),+ },children: [- Text(t.receiveTab.infoBox.subnetMask),- const SizedBox(width: 10),- Text(networkInfo?.netMask ?? t.general.unknown),+ TableRow(+ children: [+ Text(t.receiveTab.infoBox.alias),+ const SizedBox(width: 10),+ Text(serverState?.alias ?? '-'),+ ],+ ),+ TableRow(+ children: [+ Text(t.receiveTab.infoBox.ip),+ const SizedBox(width: 10),+ Text(networkInfo?.localIp ?? t.general.unknown),+ ],+ ),+ TableRow(+ children: [+ Text(t.receiveTab.infoBox.port),+ const SizedBox(width: 10),+ Text(serverState?.port.toString() ?? '-'),+ ],+ ),+ TableRow(+ children: [+ Text(t.receiveTab.infoBox.subnetMask),+ const SizedBox(width: 10),+ Text(networkInfo?.netMask ?? t.general.unknown),+ ],+ ),],),- ],+ ),),),- ),+ const SizedBox(height: 15),+ ],),- const SizedBox(height: 15),- ],+ ),),);}diff --git a/lib/pages/tabs/send_tab.dart b/lib/pages/tabs/send_tab.dartindex b1d5157a..f6b98ea9 100644--- a/lib/pages/tabs/send_tab.dart+++ b/lib/pages/tabs/send_tab.dart@@ -18,6 +18,7 @@ import 'package:localsend_app/widget/dialogs/address_input_dialog.dart';import 'package:localsend_app/widget/dialogs/no_files_dialog.dart';import 'package:localsend_app/widget/file_thumbnail.dart';import 'package:localsend_app/widget/list_tile/device_list_tile.dart';+import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:localsend_app/widget/rotating_widget.dart';import 'package:routerino/routerino.dart';@@ -62,7 +63,7 @@ class _SendTabState extends ConsumerState<SendTab> {FilePickerOption.text,];- return ListView(+ return ResponsiveListView(padding: const EdgeInsets.symmetric(horizontal: 15),children: [const SizedBox(height: 20),diff --git a/lib/pages/tabs/settings_tab.dart b/lib/pages/tabs/settings_tab.dartindex 4bb42195..160ebab9 100644--- a/lib/pages/tabs/settings_tab.dart+++ b/lib/pages/tabs/settings_tab.dart@@ -13,6 +13,7 @@ import 'package:localsend_app/util/sleep.dart';import 'package:localsend_app/util/snackbar.dart';import 'package:localsend_app/widget/custom_dropdown_button.dart';import 'package:localsend_app/widget/local_send_logo.dart';+import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:routerino/routerino.dart';class SettingsTab extends ConsumerStatefulWidget {@@ -38,7 +39,7 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {Widget build(BuildContext context) {final settings = ref.watch(settingsProvider);final serverState = ref.watch(serverProvider);- return ListView(+ return ResponsiveListView(padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 40),children: [Padding(diff --git a/lib/widget/responsive_list_view.dart b/lib/widget/responsive_list_view.dartnew file mode 100644index 00000000..1c10a50c--- /dev/null+++ b/lib/widget/responsive_list_view.dart@@ -0,0 +1,46 @@+import 'package:flutter/material.dart';+import 'package:responsive_builder/responsive_builder.dart';++class ResponsiveListView extends StatelessWidget {+ static const defaultMaxWidth = 550.0;+ static const defaultBreakpoints = ScreenBreakpoints(tablet: 600, desktop: 700, watch: 300);++ final double maxWidth;+ final ScrollController? controller;+ final EdgeInsets padding;+ final EdgeInsets desktopPadding;+ final List<Widget> children;++ const ResponsiveListView({+ this.maxWidth = defaultMaxWidth,+ this.controller,+ required this.padding,+ EdgeInsets? tabletPadding,+ required this.children,+ Key? key,+ }) : desktopPadding = tabletPadding ?? const EdgeInsets.symmetric(horizontal: 10, vertical: 50),+ super(key: key);++ @override+ Widget build(BuildContext context) {+ return SingleChildScrollView(+ controller: controller,+ child: Center(+ child: ConstrainedBox(+ constraints: BoxConstraints(maxWidth: maxWidth),+ child: ResponsiveBuilder(+ breakpoints: defaultBreakpoints,+ builder: (context, sizingInformation) {+ return Padding(+ padding: sizingInformation.isDesktop ? desktopPadding : padding,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: children,+ ),+ );+ }),+ ),+ ),+ );+ }+}diff --git a/pubspec.lock b/pubspec.lockindex b1f818f6..dfb78417 100644--- a/pubspec.lock+++ b/pubspec.lock@@ -800,6 +800,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "1.2.1"+ responsive_builder:+ dependency: "direct main"+ description:+ name: responsive_builder+ url: "https://pub.dartlang.org"+ source: hosted+ version: "0.4.3"riverpod:dependency: transitivedescription:diff --git a/pubspec.yaml b/pubspec.yamlindex dd045a92..4a531094 100644--- a/pubspec.yaml+++ b/pubspec.yaml@@ -31,6 +31,7 @@ dependencies:package_info_plus: 3.0.2path_provider: 2.0.11permission_handler: 10.2.0+ responsive_builder: 0.4.3routerino: 0.2.0share_handler: 0.0.16shared_preferences: 2.0.15