Scaffold.of -> ScaffoldMessenger.of
This commit is contained in:
parent
c722bbe4a9
commit
0bcc364ee5
|
@ -23,7 +23,7 @@ VoidCallback Function(
|
|||
if (any && store.hasNoAccount ||
|
||||
!any && store.isAnonymousFor(instanceHost)) {
|
||||
return () {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(message ?? 'you have to be logged in to do that'),
|
||||
action: SnackBarAction(
|
||||
label: 'log in',
|
||||
|
|
|
@ -15,9 +15,9 @@ import 'add_instance.dart';
|
|||
/// A modal where an account can be added for a given instance
|
||||
class AddAccountPage extends HookWidget {
|
||||
final String instanceHost;
|
||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
|
||||
AddAccountPage({@required this.instanceHost}) : assert(instanceHost != null);
|
||||
const AddAccountPage({@required this.instanceHost})
|
||||
: assert(instanceHost != null);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -48,7 +48,7 @@ class AddAccountPage extends HookWidget {
|
|||
);
|
||||
Navigator.of(context).pop();
|
||||
} on Exception catch (err) {
|
||||
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ class AddAccountPage extends HookWidget {
|
|||
}
|
||||
|
||||
return Scaffold(
|
||||
key: scaffoldKey,
|
||||
appBar: AppBar(
|
||||
leading: const CloseButton(),
|
||||
title: const Text('Add account'),
|
||||
|
@ -101,7 +100,7 @@ class AddAccountPage extends HookWidget {
|
|||
onTap: () async {
|
||||
final value = await showCupertinoModalPopup<String>(
|
||||
context: context,
|
||||
builder: (context) => AddInstancePage(),
|
||||
builder: (context) => const AddInstancePage(),
|
||||
);
|
||||
Navigator.of(context).pop(value);
|
||||
},
|
||||
|
|
|
@ -10,9 +10,7 @@ import '../widgets/fullscreenable_image.dart';
|
|||
|
||||
/// A page that let's user add a new instance. Pops a url of the added instance
|
||||
class AddInstancePage extends HookWidget {
|
||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
|
||||
AddInstancePage();
|
||||
const AddInstancePage();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -55,14 +53,13 @@ class AddInstancePage extends HookWidget {
|
|||
await accountsStore.addInstance(inst, assumeValid: true);
|
||||
Navigator.of(context).pop(inst);
|
||||
} on Exception catch (err) {
|
||||
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
key: scaffoldKey,
|
||||
appBar: AppBar(
|
||||
leading: const CloseButton(),
|
||||
title: const Text('Add instance'),
|
||||
|
|
|
@ -110,7 +110,7 @@ class CommunitiesTab extends HookWidget {
|
|||
]);
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
Scaffold.of(context)
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ class _CommunitySubscribeToggle extends HookWidget {
|
|||
));
|
||||
subbed.value = !subbed.value;
|
||||
} on Exception catch (err) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('Failed to ${subbed.value ? 'un' : ''}follow: $err'),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ class CommunityPage extends HookWidget {
|
|||
title: const Text('Open in browser'),
|
||||
onTap: () async => await ul.canLaunch(community.community.actorId)
|
||||
? ul.launch(community.community.actorId)
|
||||
: Scaffold.of(context).showSnackBar(
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("can't open in browser"))),
|
||||
),
|
||||
ListTile(
|
||||
|
@ -488,7 +488,7 @@ class _FollowButton extends HookWidget {
|
|||
isSubbed.value = !isSubbed.value;
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning),
|
||||
|
|
|
@ -44,10 +44,8 @@ class CreatePostFab extends HookWidget {
|
|||
class CreatePostPage extends HookWidget {
|
||||
final CommunityView community;
|
||||
|
||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
|
||||
CreatePostPage() : community = null;
|
||||
CreatePostPage.toCommunity(this.community);
|
||||
const CreatePostPage() : community = null;
|
||||
const CreatePostPage.toCommunity(this.community);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -100,7 +98,7 @@ class CreatePostPage extends HookWidget {
|
|||
print(urlController.text);
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
scaffoldKey.currentState.showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Failed to upload image')));
|
||||
} finally {
|
||||
imageUploadLoading.value = false;
|
||||
|
@ -229,7 +227,7 @@ class CreatePostPage extends HookWidget {
|
|||
|
||||
handleSubmit() async {
|
||||
if (selectedCommunity.value == null || titleController.text.isEmpty) {
|
||||
scaffoldKey.currentState.showSnackBar(const SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('Choosing a community and a title is required'),
|
||||
));
|
||||
return;
|
||||
|
@ -253,14 +251,13 @@ class CreatePostPage extends HookWidget {
|
|||
return;
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
scaffoldKey.currentState
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('Failed to post')));
|
||||
}
|
||||
delayed.cancel();
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
key: scaffoldKey,
|
||||
appBar: AppBar(
|
||||
leading: const CloseButton(),
|
||||
actions: [
|
||||
|
|
|
@ -78,7 +78,7 @@ class FullPostPage extends HookWidget {
|
|||
await fullPostRefreshable.refresh();
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(e.toString()),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ class InstancePage extends HookWidget {
|
|||
onTap: () async => await ul
|
||||
.canLaunch('https://${site.instanceHost}')
|
||||
? ul.launch('https://${site.instanceHost}')
|
||||
: Scaffold.of(context).showSnackBar(
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("can't open in browser"))),
|
||||
),
|
||||
ListTile(
|
||||
|
|
|
@ -133,11 +133,11 @@ class _ManageAccount extends HookWidget {
|
|||
informAcceptedAvatarRef.current();
|
||||
informAcceptedBannerRef.current();
|
||||
|
||||
Scaffold.of(context).showSnackBar(const SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('User settings saved'),
|
||||
));
|
||||
} on Exception catch (err) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
} finally {
|
||||
|
@ -190,7 +190,7 @@ class _ManageAccount extends HookWidget {
|
|||
accountsStore.removeAccount(user.instanceHost, user.name);
|
||||
Navigator.of(context).pop();
|
||||
} on Exception catch (err) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ class _ImagePicker extends HookWidget {
|
|||
onChange?.call(url.value);
|
||||
}
|
||||
} on Exception catch (_) {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Failed to upload image')));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,10 @@ import '../widgets/bottom_modal.dart';
|
|||
/// View to interact with a media object. Zoom in/out, download, share, etc.
|
||||
class MediaViewPage extends HookWidget {
|
||||
final String url;
|
||||
final GlobalKey<ScaffoldState> _key = GlobalKey();
|
||||
static const yThreshold = 150;
|
||||
static const speedThreshold = 45;
|
||||
|
||||
MediaViewPage(this.url);
|
||||
const MediaViewPage(this.url);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -30,7 +29,7 @@ class MediaViewPage extends HookWidget {
|
|||
final prevOffset = usePrevious(offset.value);
|
||||
|
||||
notImplemented() {
|
||||
_key.currentState.showSnackBar(const SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text("this feature hasn't been implemented yet 😰")));
|
||||
}
|
||||
|
||||
|
@ -64,7 +63,6 @@ class MediaViewPage extends HookWidget {
|
|||
}
|
||||
|
||||
return Scaffold(
|
||||
key: _key,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
backgroundColor:
|
||||
|
|
|
@ -180,7 +180,7 @@ class AccountsConfigPage extends HookWidget {
|
|||
labelBackgroundColor: theme.canvasColor,
|
||||
label: 'Add instance',
|
||||
onTap: () => showCupertinoModalPopup(
|
||||
context: context, builder: (_) => AddInstancePage()),
|
||||
context: context, builder: (_) => const AddInstancePage()),
|
||||
),
|
||||
],
|
||||
child: const Icon(Icons.add),
|
||||
|
@ -196,7 +196,7 @@ class AccountsConfigPage extends HookWidget {
|
|||
child: TextButton.icon(
|
||||
onPressed: () => showCupertinoModalPopup(
|
||||
context: context,
|
||||
builder: (_) => AddInstancePage(),
|
||||
builder: (_) => const AddInstancePage(),
|
||||
),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Add instance'),
|
||||
|
|
|
@ -16,11 +16,9 @@ class WriteMessagePage extends HookWidget {
|
|||
/// if it's non null then this page is used for edit
|
||||
final PrivateMessage privateMessage;
|
||||
|
||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
|
||||
final bool _isEdit;
|
||||
|
||||
WriteMessagePage.send({
|
||||
const WriteMessagePage.send({
|
||||
@required this.recipient,
|
||||
@required this.instanceHost,
|
||||
}) : assert(recipient != null),
|
||||
|
@ -58,7 +56,7 @@ class WriteMessagePage extends HookWidget {
|
|||
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(e.toString()),
|
||||
));
|
||||
}
|
||||
|
@ -76,7 +74,7 @@ class WriteMessagePage extends HookWidget {
|
|||
// containing this widget adds new message?
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(e.toString()),
|
||||
));
|
||||
} finally {
|
||||
|
@ -106,7 +104,6 @@ class WriteMessagePage extends HookWidget {
|
|||
);
|
||||
|
||||
return Scaffold(
|
||||
key: scaffoldKey,
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
leading: const CloseButton(),
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:lemmy_api_client/v2.dart';
|
|||
import '../hooks/delayed_loading.dart';
|
||||
|
||||
/// Executes an API action that uses [DelayedLoading], has a try-catch
|
||||
/// that displays a [SnackBar] on the Scaffold.of(context) when the action fails
|
||||
/// that displays a [SnackBar] when the action fails
|
||||
Future<void> delayedAction<T>({
|
||||
@required BuildContext context,
|
||||
@required DelayedLoading delayedLoading,
|
||||
|
@ -26,7 +26,8 @@ Future<void> delayedAction<T>({
|
|||
onSuccess?.call(val);
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
}
|
||||
cleanup?.call(val);
|
||||
delayedLoading.cancel();
|
||||
|
|
|
@ -143,7 +143,7 @@ class CommentWidget extends HookWidget {
|
|||
title: const Text('Open in browser'),
|
||||
onTap: () async => await ul.canLaunch(com.comment.link)
|
||||
? ul.launch(com.comment.link)
|
||||
: Scaffold.of(context).showSnackBar(
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("can't open in browser"))),
|
||||
),
|
||||
ListTile(
|
||||
|
@ -271,7 +271,7 @@ class CommentWidget extends HookWidget {
|
|||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(
|
||||
text: commentTree.comment.comment.content))
|
||||
.then((_) => Scaffold.of(context).showSnackBar(
|
||||
.then((_) => ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('comment copied to clipboard'))));
|
||||
}),
|
||||
|
|
|
@ -36,14 +36,15 @@ class MarkdownText extends StatelessWidget {
|
|||
),
|
||||
onTapLink: (href) {
|
||||
linkLauncher(context: context, url: href, instanceHost: instanceHost)
|
||||
.catchError((e) => Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning),
|
||||
Text("couldn't open link, ${e.toString()}"),
|
||||
],
|
||||
),
|
||||
)));
|
||||
.catchError(
|
||||
(e) => ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning),
|
||||
Text("couldn't open link, ${e.toString()}"),
|
||||
],
|
||||
),
|
||||
)));
|
||||
},
|
||||
imageBuilder: (uri, title, alt) => FullscreenableImage(
|
||||
url: uri.toString(),
|
||||
|
|
|
@ -70,7 +70,7 @@ class PostWidget extends HookWidget {
|
|||
title: const Text('Open in browser'),
|
||||
onTap: () async => await ul.canLaunch(post.post.apId)
|
||||
? ul.launch(post.post.apId)
|
||||
: Scaffold.of(context).showSnackBar(
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("can't open in browser"))),
|
||||
),
|
||||
ListTile(
|
||||
|
@ -506,7 +506,7 @@ class _Voting extends HookWidget {
|
|||
myVote.value = res.myVote ?? VoteType.none;
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
Scaffold.of(context)
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('voting failed :(')));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class SavePostButton extends HookWidget {
|
|||
isSaved.value = res.saved;
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
Scaffold.of(context)
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('saving failed :(')));
|
||||
}
|
||||
loading.cancel();
|
||||
|
|
|
@ -15,10 +15,8 @@ class WriteComment extends HookWidget {
|
|||
final Post post;
|
||||
final Comment comment;
|
||||
|
||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
||||
|
||||
WriteComment.toPost(this.post) : comment = null;
|
||||
WriteComment.toComment({@required this.comment, @required this.post})
|
||||
const WriteComment.toPost(this.post) : comment = null;
|
||||
const WriteComment.toComment({@required this.comment, @required this.post})
|
||||
: assert(comment != null),
|
||||
assert(post != null);
|
||||
|
||||
|
@ -67,14 +65,13 @@ class WriteComment extends HookWidget {
|
|||
Navigator.of(context).pop(res.commentView);
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e) {
|
||||
scaffoldKey.currentState.showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Failed to post comment')));
|
||||
}
|
||||
delayed.cancel();
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
key: scaffoldKey,
|
||||
appBar: AppBar(
|
||||
leading: const CloseButton(),
|
||||
actions: [
|
||||
|
|
Loading…
Reference in New Issue