Browse Source

replaced deprecated members (#99)

Co-authored-by: Aman Nanda <amannanda8@gmail.com>
Reviewed-on: yarnsocial/goryon#99
Co-authored-by: amanxnanda <amanxnanda@noreply@mills.io>
Co-committed-by: amanxnanda <amanxnanda@noreply@mills.io>
pull/104/head
amanxnanda 2 months ago
committed by James Mills
parent
commit
e3c853d647
  1. 19
      .vscode/launch.json
  2. 2
      lib/models.g.dart
  3. 4
      lib/screens/auth_widget.dart
  4. 1
      lib/screens/conversation.dart
  5. 4
      lib/screens/follow.dart
  6. 2
      lib/screens/newtwt.dart
  7. 29
      lib/screens/profile.dart
  8. 4
      lib/screens/register.dart
  9. 4
      lib/screens/report.dart
  10. 6
      lib/screens/settings.dart
  11. 42
      lib/viewmodels.dart
  12. 42
      lib/widgets/common_widgets.dart
  13. 10
      lib/widgets/image_picker.dart

19
.vscode/launch.json

@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "goryon",
"request": "launch",
"type": "dart"
},
{
"name": "goryon (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
}
]
}

2
lib/models.g.dart

@ -95,7 +95,7 @@ Twt _$TwtFromJson(Map<String, dynamic> json) {
? null
: DateTime.parse(json['created'] as String),
hash: json['hash'] as String?,
tags: (json['tags'] as List?)?.map((e) => e as String)?.toList(),
tags: (json['tags'] as List?)?.map((e) => e as String).toList(),
subject: json['subject'] as String?,
);
}

4
lib/screens/auth_widget.dart

@ -45,8 +45,8 @@ class _AuthWidgetState extends State<AuthWidget> {
@override
Widget build(BuildContext context) {
if (widget.snapshot!.connectionState == ConnectionState.active) {
return widget.snapshot!.hasData ? Home() : Login();
if (widget.snapshot.connectionState == ConnectionState.active) {
return widget.snapshot.hasData ? Home() : Login();
}
return Scaffold(

1
lib/screens/conversation.dart

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../strings.dart';
import '../viewmodels.dart';
import '../widgets/common_widgets.dart';
import 'newtwt.dart';

4
lib/screens/follow.dart

@ -56,7 +56,7 @@ class _FollowState extends State<Follow> {
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: RaisedButton(
child: ElevatedButton(
child: const Text('OK'),
onPressed: () {
_nicknameController.clear();
@ -85,7 +85,7 @@ class _FollowState extends State<Follow> {
),
);
} on http.ClientException catch (e) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text(e.message)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.message)));
}
}

2
lib/screens/newtwt.dart

@ -122,7 +122,7 @@ class _NewTwtFormState extends State<NewTwtForm> {
text: textEditingController.value.text + '![]($imageURL)',
);
} catch (_) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'An error has occurred while uploading an image. Please try again',

29
lib/screens/profile.dart

@ -37,7 +37,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
try {
await context.read<ProfileViewModel>().refreshPost();
} catch (e) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to refresh post'),
),
@ -48,13 +48,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
Future _follow(String? nick, String url, BuildContext context) async {
try {
await context.read<AuthViewModel>().follow(nick, url);
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Successfully followed $nick'),
),
);
} catch (e) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to follow $nick'),
),
@ -66,13 +66,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
Future _unfollow(String? nick, BuildContext context) async {
try {
await context.read<AuthViewModel>().unfollow(nick);
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Successfully unfollowed $nick'),
),
);
} catch (e) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to unfollow $nick'),
),
@ -85,13 +85,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
try {
await context.read<ProfileViewModel>().mute();
await context.read<ProfileViewModel>().refreshPost();
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Successfully muted user/feed'),
),
);
} catch (e) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to mute user/feed'),
),
@ -104,13 +104,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
try {
await context.read<ProfileViewModel>().unmute();
await context.read<ProfileViewModel>().refreshPost();
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Successfully unmuted user/feed'),
),
);
} catch (e) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to unmute user/feed'),
),
@ -255,8 +255,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
});
};
if (snapshot.connectionState ==
ConnectionState.waiting) {
if (snapshot.connectionState == ConnectionState.waiting) {
leading = SizedSpinner();
onTap = null;
}
@ -316,7 +315,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
nick: vm.profile!.username,
url: vm.profile!.uri.toString(),
afterSubmit: () {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Your report has successfully submitted',
@ -406,8 +405,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
children: [
Text('Failed to load profile: ' + snapshot.error.toString()),
SizedBox(height: 32),
RaisedButton(
color: Theme.of(context).colorScheme.error,
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).colorScheme.error,
),
onPressed: () {
setState(() {
_fetchProfileFuture = _fetchProfile();

4
lib/screens/register.dart

@ -36,7 +36,7 @@ class _RegisterState extends State<Register> {
);
Navigator.pop(context, true);
} catch (e) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
rethrow;
}
}
@ -142,7 +142,7 @@ class _RegisterState extends State<Register> {
return Center(child: CircularProgressIndicator());
}
return RaisedButton(
return ElevatedButton(
onPressed: !_communityGuidelineToggle
? null
: () {

4
lib/screens/report.dart

@ -63,7 +63,7 @@ class _ReportState extends State<Report> {
);
widget.afterSubmit();
} catch (e) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to submit report'),
),
@ -187,7 +187,7 @@ class _ReportState extends State<Report> {
builder: (context, snapshot) {
final isLoading =
snapshot.connectionState == ConnectionState.waiting;
return RaisedButton(
return ElevatedButton(
onPressed: isLoading
? null
: () {

6
lib/screens/settings.dart

@ -123,13 +123,13 @@ class _SettingsBodyState extends State<SettingsBody> {
_emailController.text,
_isFollowersPubliclyVisible!,
_isFollowingPubliclyVisible!);
Scaffold.of(context).showSnackBar(SnackBar(
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Successfully saved user settings'),
));
await context.read<AuthViewModel>().getAppUser();
CachedNetworkImage.evictFromCache(widget.imageURL!);
} catch (e) {
Scaffold.of(context).showSnackBar(SnackBar(
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Failed to save user settings'),
));
rethrow;
@ -239,7 +239,7 @@ class _SettingsBodyState extends State<SettingsBody> {
return Center(child: CircularProgressIndicator());
}
return RaisedButton(
return ElevatedButton(
onPressed: () {
setState(() {
_saveSettingsFuture = save();

42
lib/viewmodels.dart

@ -118,16 +118,16 @@ class TimelineViewModel extends ChangeNotifier {
}
void gotoNextPage() async {
if (_lastTimelineResponse.pagerResponse!.currentPage ==
_lastTimelineResponse.pagerResponse!.maxPages) {
if (_lastTimelineResponse.pagerResponse.currentPage ==
_lastTimelineResponse.pagerResponse.maxPages) {
return;
}
fetchMoreState = FetchState.Loading;
try {
final page = _lastTimelineResponse.pagerResponse!.currentPage! + 1;
final page = _lastTimelineResponse.pagerResponse.currentPage! + 1;
_lastTimelineResponse = await _api.timeline(page);
_twts = [..._twts!, ..._lastTimelineResponse.twts!];
_twts = [..._twts!, ..._lastTimelineResponse.twts];
fetchMoreState = FetchState.Done;
} catch (e) {
fetchMoreState = FetchState.Error;
@ -182,16 +182,16 @@ class MentionsViewModel extends ChangeNotifier {
}
void gotoNextPage() async {
if (_lastMentionsResponse.pagerResponse!.currentPage ==
_lastMentionsResponse.pagerResponse!.maxPages) {
if (_lastMentionsResponse.pagerResponse.currentPage ==
_lastMentionsResponse.pagerResponse.maxPages) {
return;
}
fetchMoreState = FetchState.Loading;
try {
final page = _lastMentionsResponse.pagerResponse!.currentPage! + 1;
final page = _lastMentionsResponse.pagerResponse.currentPage! + 1;
_lastMentionsResponse = await _api.mentions(page);
_twts = [..._twts!, ..._lastMentionsResponse.twts!];
_twts = [..._twts!, ..._lastMentionsResponse.twts];
fetchMoreState = FetchState.Done;
} catch (e) {
fetchMoreState = FetchState.Error;
@ -245,16 +245,16 @@ class DiscoverViewModel extends ChangeNotifier {
}
void gotoNextPage() async {
if (_lastTimelineResponse.pagerResponse!.currentPage ==
_lastTimelineResponse.pagerResponse!.maxPages) {
if (_lastTimelineResponse.pagerResponse.currentPage ==
_lastTimelineResponse.pagerResponse.maxPages) {
return;
}
fetchMoreState = FetchState.Loading;
try {
final page = _lastTimelineResponse.pagerResponse!.currentPage! + 1;
final page = _lastTimelineResponse.pagerResponse.currentPage! + 1;
_lastTimelineResponse = await _api.discover(page);
_twts = [..._twts!, ..._lastTimelineResponse.twts!];
_twts = [..._twts!, ..._lastTimelineResponse.twts];
fetchMoreState = FetchState.Done;
} catch (e) {
fetchMoreState = FetchState.Error;
@ -329,16 +329,16 @@ class ProfileViewModel extends ChangeNotifier {
}
Future<void> gotoNextPage() async {
if (_lastTimelineResponse.pagerResponse!.currentPage ==
_lastTimelineResponse.pagerResponse!.maxPages) {
if (_lastTimelineResponse.pagerResponse.currentPage ==
_lastTimelineResponse.pagerResponse.maxPages) {
return;
}
fetchMoreState = FetchState.Loading;
try {
final page = _lastTimelineResponse.pagerResponse!.currentPage! + 1;
final page = _lastTimelineResponse.pagerResponse.currentPage! + 1;
_lastTimelineResponse = await _api.getUserTwts(page, profile!.username);
_twts = [..._twts!, ..._lastTimelineResponse.twts!];
_twts = [..._twts!, ..._lastTimelineResponse.twts];
fetchMoreState = FetchState.Done;
} catch (e) {
fetchMoreState = FetchState.Error;
@ -363,8 +363,6 @@ class ThemeViewModel extends ChangeNotifier {
ThemeMode? _themeMode;
ThemeViewModel(this._sharedPreferences) {
assert(this._sharedPreferences != null);
_themeMode = ThemeMode.values[
(_sharedPreferences.getInt(ThemeViewModel.ThemeModeKey) ??
0)]; // Uses ThemeMode.system by default
@ -436,17 +434,17 @@ class ConversationViewModel extends ChangeNotifier {
}
void gotoNextPage() async {
if (_lastMentionsResponse.pagerResponse!.currentPage ==
_lastMentionsResponse.pagerResponse!.maxPages) {
if (_lastMentionsResponse.pagerResponse.currentPage ==
_lastMentionsResponse.pagerResponse.maxPages) {
return;
}
fetchMoreState = FetchState.Loading;
try {
final page = _lastMentionsResponse.pagerResponse!.currentPage! + 1;
final page = _lastMentionsResponse.pagerResponse.currentPage! + 1;
_lastMentionsResponse =
await _api.fetchConversation(_sourceTwt.cleanSubject, page);
_twts = [..._twts!, ..._lastMentionsResponse.twts!];
_twts = [..._twts!, ..._lastMentionsResponse.twts];
fetchMoreState = FetchState.Done;
} catch (e) {
fetchMoreState = FetchState.Error;

42
lib/widgets/common_widgets.dart

@ -65,8 +65,7 @@ class SizedSpinner extends StatelessWidget {
final double height;
final double width;
const SizedSpinner({Key? key, this.height = 16, this.width = 16})
: super(key: key);
const SizedSpinner({Key? key, this.height = 16, this.width = 16}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -134,9 +133,7 @@ class AuthWidgetBuilder extends StatelessWidget {
}
class AppDrawer extends StatelessWidget {
const AppDrawer(
{Key? key, required this.activatedRoute, this.avatarRadius = 35})
: super(key: key);
const AppDrawer({Key? key, required this.activatedRoute, this.avatarRadius = 35}) : super(key: key);
final String activatedRoute;
final double avatarRadius;
@ -240,7 +237,7 @@ class PostActions extends StatelessWidget {
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Center(
child: RaisedButton(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
@ -292,9 +289,7 @@ class _PostListState extends State<PostList> {
}
void initiateLoadMoreOnScroll() {
if (_scrollController.position.pixels >
_scrollController.position.maxScrollExtent * 0.9 &&
widget.fetchMoreState == FetchState.Done) {
if (_scrollController.position.pixels > _scrollController.position.maxScrollExtent * 0.9 && widget.fetchMoreState == FetchState.Done) {
widget.gotoNextPage();
}
}
@ -363,8 +358,7 @@ class _PostListState extends State<PostList> {
title: title,
videoURL: thumbnailURI
.replace(
path:
"${thumbnailURI.path}.${Platform.isIOS ? 'mp4' : 'webm'}",
path: "${thumbnailURI.path}.${Platform.isIOS ? 'mp4' : 'webm'}",
)
.toString(),
),
@ -378,7 +372,7 @@ class _PostListState extends State<PostList> {
return;
}
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(appStrings.failLaunchImageToBrowser),
),
@ -423,7 +417,7 @@ class _PostListState extends State<PostList> {
return;
}
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('${appStrings.failLaunch} $link'),
),
@ -475,16 +469,13 @@ class _PostListState extends State<PostList> {
Row(
children: [
Text(
Jiffy(twt.createdTime!.toLocal())
.format('jm'),
style:
Theme.of(context).textTheme.bodyText2,
Jiffy(twt.createdTime!.toLocal()).format('jm'),
style: Theme.of(context).textTheme.bodyText2,
),
SizedBox(width: 8),
Text(
'(${Jiffy(twt.createdTime).fromNow()})',
style:
Theme.of(context).textTheme.bodyText2,
style: Theme.of(context).textTheme.bodyText2,
),
],
),
@ -578,8 +569,7 @@ class _PostListState extends State<PostList> {
),
),
SizedBox(width: 8),
if (widget.showConversationButton &&
twt.subject!.isNotEmpty)
if (widget.showConversationButton && twt.subject!.isNotEmpty)
OutlinedButton(
style: OutlinedButton.styleFrom(
shape: StadiumBorder(),
@ -694,8 +684,10 @@ class ErrorMessage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
description!,
RaisedButton(
color: Theme.of(context).colorScheme.error,
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).colorScheme.error,
),
onPressed: onButtonPressed,
child: buttonChild,
)
@ -735,9 +727,7 @@ class DropdownFormField<T> extends FormField<T> {
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: state.hasError
? theme.errorColor
: Color(0xFFBDBDBD),
color: state.hasError ? theme.errorColor : Color(0xFFBDBDBD),
width: state.hasError ? 1.0 : 0.0,
),
),

10
lib/widgets/image_picker.dart

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:image_picker/image_picker.dart';
Future<PickedFile?> getImage(
Future<XFile?> getImage(
BuildContext context,
ImagePicker picker,
) async {
@ -36,10 +36,10 @@ Future<PickedFile?> getImage(
);
})) {
case ImageSource.gallery:
return picker.getImage(source: ImageSource.gallery);
return picker.pickImage(source: ImageSource.gallery);
case ImageSource.camera:
return picker.getImage(source: ImageSource.camera);
return picker.pickImage(source: ImageSource.camera);
default:
return null;
}
return null;
}

Loading…
Cancel
Save