-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from emanuel-braz/feature/add-mobile-layout
feat: add mobile layout
- Loading branch information
Showing
7 changed files
with
302 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class LayoutUtil { | ||
static bool isMobileLayout(BuildContext context) => MediaQuery.of(context).size.width < 600; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_sp_social/data/social_qr_code.dart'; | ||
import 'package:flutter_sp_social/presentation/home/event_store.dart'; | ||
import 'package:pretty_qr_code/pretty_qr_code.dart'; | ||
|
||
class DesktopView extends StatefulWidget { | ||
final EventStore store; | ||
|
||
const DesktopView({super.key, required this.store}); | ||
|
||
@override | ||
State<DesktopView> createState() => _DesktopViewState(); | ||
} | ||
|
||
class _DesktopViewState extends State<DesktopView> { | ||
late final double _cardMaxWidth; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
final params = Uri.base.queryParameters; | ||
_cardMaxWidth = double.tryParse(params['width'] ?? '') ?? 300.0; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
alignment: Alignment.center, | ||
padding: const EdgeInsets.all(16), | ||
child: SingleChildScrollView( | ||
padding: const EdgeInsets.only(bottom: 16), | ||
child: Wrap( | ||
spacing: 16, | ||
runSpacing: 16, | ||
children: | ||
widget.store.value!.socialQrCodes.map((e) => _QRCode(socialQrCode: e, width: _cardMaxWidth)).toList()), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _QRCode extends StatelessWidget { | ||
final SocialQrCode socialQrCode; | ||
final double width; | ||
|
||
const _QRCode({required this.socialQrCode, required this.width}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MouseRegion( | ||
cursor: SystemMouseCursors.click, | ||
child: GestureDetector( | ||
onTap: () { | ||
showDialog( | ||
context: context, | ||
barrierColor: Colors.black.withOpacity(0.98), | ||
builder: (_) => AlertDialog( | ||
backgroundColor: Theme.of(context).colorScheme.surface, | ||
content: SizedBox( | ||
width: MediaQuery.sizeOf(context).height * 0.7, | ||
child: AbsorbPointer(absorbing: true, child: this), | ||
), | ||
)); | ||
}, | ||
child: Container( | ||
constraints: BoxConstraints(maxWidth: width), | ||
padding: const EdgeInsets.only(top: 16, left: 16, right: 16), | ||
decoration: BoxDecoration( | ||
color: Colors.black, | ||
borderRadius: BorderRadius.circular(16), | ||
), | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Container( | ||
padding: const EdgeInsets.all(8), | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colorScheme.surface, | ||
borderRadius: BorderRadius.circular(8), | ||
), | ||
child: PrettyQrView( | ||
qrImage: QrImage( | ||
QrCode.fromData( | ||
data: socialQrCode.qrCode, | ||
errorCorrectLevel: QrErrorCorrectLevel.H, | ||
), | ||
), | ||
decoration: PrettyQrDecoration( | ||
shape: PrettyQrSmoothSymbol( | ||
color: socialQrCode.color != null | ||
? Color(int.parse(socialQrCode.color!, radix: 16)) | ||
: Theme.of(context).colorScheme.primary, | ||
roundFactor: 0, | ||
), | ||
image: PrettyQrDecorationImage( | ||
image: socialQrCode.icon != null | ||
? NetworkImage(socialQrCode.icon!) as ImageProvider | ||
: const AssetImage('images/dash.png'), | ||
position: PrettyQrDecorationImagePosition.embedded, | ||
), | ||
)), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
socialQrCode.title, | ||
style: Theme.of(context).textTheme.headlineSmall!.copyWith( | ||
color: Theme.of(context).colorScheme.background, | ||
), | ||
textAlign: TextAlign.center, | ||
maxLines: 2, | ||
overflow: TextOverflow.ellipsis, | ||
semanticsLabel: socialQrCode.title, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_sp_social/core/utils/layout_util.dart'; | ||
import 'package:flutter_sp_social/presentation/home/event_store.dart'; | ||
import 'package:flutter_sp_social/presentation/home/home_view/desktop_view.dart'; | ||
import 'package:flutter_sp_social/presentation/home/home_view/mobile_view.dart'; | ||
|
||
class HomePageViewFactory { | ||
static Widget build(BuildContext context, EventStore store) { | ||
if (LayoutUtil.isMobileLayout(context)) { | ||
return MobileView(store: store); | ||
} else { | ||
return DesktopView(store: store); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher_string.dart'; | ||
|
||
import '../../../data/social_qr_code.dart'; | ||
import '../event_store.dart'; | ||
|
||
class MobileView extends StatelessWidget { | ||
final EventStore store; | ||
|
||
const MobileView({super.key, required this.store}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListView.separated( | ||
padding: const EdgeInsets.all(16), | ||
itemCount: store.value!.socialQrCodes.length, | ||
separatorBuilder: (context, index) => const SizedBox(height: 16), | ||
itemBuilder: (context, index) => ListTileWidget(socialQrCode: store.value!.socialQrCodes[index]), | ||
); | ||
} | ||
} | ||
|
||
class ListTileWidget extends StatelessWidget { | ||
final SocialQrCode socialQrCode; | ||
const ListTileWidget({super.key, required this.socialQrCode}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
final textTheme = theme.textTheme; | ||
|
||
Widget icon = socialQrCode.icon != null | ||
? Image.network(socialQrCode.icon!, fit: BoxFit.fitWidth, width: 48, height: 48) | ||
: Image.asset('images/dash.png', width: 48, height: 48, fit: BoxFit.fitWidth); | ||
|
||
return MouseRegion( | ||
cursor: SystemMouseCursors.click, | ||
child: GestureDetector( | ||
onTap: () => launchUrlString(socialQrCode.qrCode), | ||
child: Container( | ||
clipBehavior: Clip.antiAlias, | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(8), | ||
border: Border.all(color: theme.colorScheme.primary), | ||
), | ||
padding: const EdgeInsets.all(16), | ||
child: Row( | ||
children: [ | ||
icon, | ||
const SizedBox(width: 16), | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text(socialQrCode.title, style: textTheme.headlineSmall), | ||
Text(socialQrCode.qrCode, style: textTheme.bodySmall), | ||
], | ||
), | ||
), | ||
], | ||
)), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.