Skip to content

Commit

Permalink
feat: add ShareReceive to login page
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Jun 8, 2023
1 parent 5471a96 commit aceef38
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 53 deletions.
20 changes: 1 addition & 19 deletions app/lib/common/widgets/share_receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ class ShareReceive extends StatefulWidget {

class _ShareReceiveState extends State<ShareReceive> {
late StreamSubscription _intentDataStreamSubscription;
List<SharedFile>? list;
@override
void initState() {
super.initState();
// For sharing images coming from outside the app while the app is in
// the memory
_intentDataStreamSubscription = FlutterSharingIntent.instance.getMediaStream()
.listen((sharedFiles) {
setState(() {
list = sharedFiles;
});
// ignore: avoid_print
print(
"Shared: getMediaStream ${sharedFiles.map((f) => f.value).join(",")}");
Expand All @@ -36,26 +32,12 @@ class _ShareReceiveState extends State<ShareReceive> {
// ignore: avoid_print
print(
"Shared: getInitialMedia ${sharedFiles.map((f) => f.value).join(",")}");
setState(() {
list = sharedFiles;
});
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 24),
child: Text('Sharing data: \n${list?.join("\n\n")}\n')),
),
),
);
return SizedBox.shrink();
}
@override
void dispose() {
Expand Down
74 changes: 40 additions & 34 deletions app/lib/login/pages/login.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:dropdown_button2/dropdown_button2.dart';

import '../../../common/module.dart';
import '../../../common/widgets/share_receive.dart';
import '../models/lab.dart';
import 'cubit.dart';

Expand All @@ -16,44 +17,49 @@ class LoginPage extends HookWidget {
Widget build(BuildContext context) {
final dropdownValue = useState(labs.first.name);

return BlocProvider(
create: (context) => cubit ?? LoginPageCubit(),
child: BlocBuilder<LoginPageCubit, LoginPageState>(
builder: (context, state) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
Positioned.fill(
child: Align(
alignment: Alignment.center,
child: SvgPicture.asset(
'assets/images/logo.svg',
return Stack(
children: [
ShareReceive(),
BlocProvider(
create: (context) => cubit ?? LoginPageCubit(),
child: BlocBuilder<LoginPageCubit, LoginPageState>(
builder: (context, state) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
Positioned.fill(
child: Align(
alignment: Alignment.center,
child: SvgPicture.asset(
'assets/images/logo.svg',
),
),
),
),
),
Positioned(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(16),
child: state.when(
initial: () =>
_buildInitialScreen(context, dropdownValue),
loadingUserData: CircularProgressIndicator.new,
loadedUserData: () => _buildLoadedScreen(context),
error: (message) =>
_buildErrorScreen(context, message),
Positioned(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(16),
child: state.when(
initial: () =>
_buildInitialScreen(context, dropdownValue),
loadingUserData: CircularProgressIndicator.new,
loadedUserData: () => _buildLoadedScreen(context),
error: (message) =>
_buildErrorScreen(context, message),
),
),
),
),
),
],
),
],
),
),
);
},
),
),
);
},
),
),
],
);
}

Expand Down

0 comments on commit aceef38

Please sign in to comment.