feat(post-creation): add post overview screen before posting

This commit is contained in:
FahadFahim71 2024-02-21 15:37:05 +01:00
parent eca34a9502
commit 2225a2a2c2
13 changed files with 144 additions and 21 deletions

View file

@ -1,7 +1,9 @@
## 2.0.1
## 2.1.0
- Fixed multiline textfield not being dismissible.
- Fixed liking a new post you created.
- Added options to require image and enforce content length in post creation
- Added post overview screen before creating post
## 1.0.0 - November 27 2023

View file

@ -43,8 +43,12 @@ class _MyHomePageState extends State<MyHomePage> {
children: [
FloatingActionButton(
heroTag: 'btn1',
onPressed: () =>
createPost(context, timelineService, timelineOptions),
onPressed: () => createPost(
context,
timelineService,
timelineOptions,
getConfig(timelineService),
),
child: const Icon(
Icons.edit,
color: Colors.white,

View file

@ -45,7 +45,12 @@ class _MyHomePageState extends State<MyHomePage> {
FloatingActionButton(
heroTag: 'btn1',
onPressed: () {
createPost(context, timelineService, timelineOptions);
createPost(
context,
timelineService,
timelineOptions,
getConfig(timelineService),
);
},
child: const Icon(
Icons.edit,

View file

@ -3,9 +3,10 @@ import 'package:flutter_timeline/flutter_timeline.dart';
TimelineUserStoryConfiguration getConfig(TimelineService service) {
return TimelineUserStoryConfiguration(
service: service,
userId: 'test_user',
optionsBuilder: (context) => options);
service: service,
userId: 'test_user',
optionsBuilder: (context) => options,
);
}
var options = TimelineOptions(
@ -33,9 +34,39 @@ var options = TimelineOptions(
),
);
void createPost(BuildContext context, TimelineService service,
TimelineOptions options) async {
await Navigator.push(
void navigateToOverview(
BuildContext context,
TimelineService service,
TimelineOptions options,
TimelinePost post,
) {
if (context.mounted) {
Navigator.of(context).pop();
}
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TimelinePostOverviewScreen(
timelinePost: post,
options: options,
service: service,
onPostSubmit: (post) {
service.postService.createPost(post);
if (context.mounted) {
Navigator.of(context).pop();
}
},
),
),
);
}
void createPost(
BuildContext context,
TimelineService service,
TimelineOptions options,
TimelineUserStoryConfiguration configuration) async {
await Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
@ -47,6 +78,9 @@ void createPost(BuildContext context, TimelineService service,
onPostCreated: (post) {
Navigator.of(context).pop();
},
onPostOverview: (post) {
navigateToOverview(context, service, options, post);
},
),
),
),

View file

@ -55,6 +55,7 @@ class TimelineUserStoryConfiguration {
this.onPostDelete,
this.filterEnabled = false,
this.postWidgetBuilder,
this.enablePostOverviewScreen = false,
});
/// The ID of the user associated with this user story configuration.
@ -84,4 +85,7 @@ class TimelineUserStoryConfiguration {
/// A function that builds a widget for a timeline post.
final Widget Function(TimelinePost post)? postWidgetBuilder;
/// Boolean to enable timeline post overview screen before submitting
final bool enablePostOverviewScreen;
}

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
name: flutter_timeline
description: Visual elements and interface combined into one package
version: 2.0.0
version: 2.1.0
publish_to: none
@ -19,13 +19,13 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_view
ref: 2.0.0
ref: 2.1.0
flutter_timeline_interface:
git:
url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_interface
ref: 2.0.0
ref: 2.1.0
dev_dependencies:
flutter_lints: ^2.0.0

View file

@ -4,7 +4,7 @@
name: flutter_timeline_firebase
description: Implementation of the Flutter Timeline interface for Firebase.
version: 2.0.0
version: 2.1.0
publish_to: none
@ -23,7 +23,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_interface
ref: 2.0.0
ref: 2.1.0
dev_dependencies:
flutter_lints: ^2.0.0

View file

@ -4,7 +4,7 @@
name: flutter_timeline_interface
description: Interface for the service of the Flutter Timeline component
version: 2.0.0
version: 2.1.0
publish_to: none

View file

@ -9,6 +9,7 @@ export 'src/config/timeline_styles.dart';
export 'src/config/timeline_theme.dart';
export 'src/config/timeline_translations.dart';
export 'src/screens/timeline_post_creation_screen.dart';
export 'src/screens/timeline_post_overview_screen.dart';
export 'src/screens/timeline_post_screen.dart';
export 'src/screens/timeline_screen.dart';
export 'src/screens/timeline_selection_screen.dart';

View file

@ -29,6 +29,8 @@ class TimelineTranslations {
required this.postLoadingError,
required this.timelineSelectionDescription,
required this.searchHint,
required this.postOverview,
required this.postIn,
});
const TimelineTranslations.empty()
@ -54,7 +56,9 @@ class TimelineTranslations {
postAt = 'at',
postLoadingError = 'Something went wrong while loading the post',
timelineSelectionDescription = 'Choose a category',
searchHint = 'Search...';
searchHint = 'Search...',
postOverview = 'Post Overview',
postIn = 'Post in';
final String noPosts;
final String noPostsWithFilter;
@ -83,6 +87,9 @@ class TimelineTranslations {
final String searchHint;
final String postOverview;
final String postIn;
TimelineTranslations copyWith({
String? noPosts,
String? noPostsWithFilter,
@ -106,6 +113,8 @@ class TimelineTranslations {
String? postLoadingError,
String? timelineSelectionDescription,
String? searchHint,
String? postOverview,
String? postIn,
}) =>
TimelineTranslations(
noPosts: noPosts ?? this.noPosts,
@ -133,5 +142,7 @@ class TimelineTranslations {
timelineSelectionDescription:
timelineSelectionDescription ?? this.timelineSelectionDescription,
searchHint: searchHint ?? this.searchHint,
postOverview: postOverview ?? this.postOverview,
postIn: postIn ?? this.postIn,
);
}

View file

@ -8,6 +8,7 @@ import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:flutter_image_picker/flutter_image_picker.dart';
import 'package:flutter_timeline_interface/flutter_timeline_interface.dart';
import 'package:flutter_timeline_view/flutter_timeline_view.dart';
import 'package:flutter_timeline_view/src/config/timeline_options.dart';
class TimelinePostCreationScreen extends StatefulWidget {
@ -17,6 +18,7 @@ class TimelinePostCreationScreen extends StatefulWidget {
required this.service,
required this.options,
this.postCategory,
this.onPostOverview,
super.key,
});
@ -33,6 +35,9 @@ class TimelinePostCreationScreen extends StatefulWidget {
/// The options for the timeline
final TimelineOptions options;
/// Nullable callback for routing to the post overview
final void Function(TimelinePost)? onPostOverview;
@override
State<TimelinePostCreationScreen> createState() =>
_TimelinePostCreationScreenState();
@ -101,8 +106,13 @@ class _TimelinePostCreationScreenState
reactionEnabled: allowComments,
image: image,
);
var newPost = await widget.service.postService.createPost(post);
widget.onPostCreated.call(newPost);
if (widget.onPostOverview != null) {
widget.onPostOverview?.call(post);
} else {
var newPost = await widget.service.postService.createPost(post);
widget.onPostCreated.call(newPost);
}
}
var theme = Theme.of(context);

View file

@ -0,0 +1,52 @@
// ignore_for_file: prefer_expression_function_bodies
import 'package:flutter/material.dart';
import 'package:flutter_timeline_interface/flutter_timeline_interface.dart';
import 'package:flutter_timeline_view/flutter_timeline_view.dart';
class TimelinePostOverviewScreen extends StatelessWidget {
const TimelinePostOverviewScreen({
required this.timelinePost,
required this.options,
required this.service,
required this.onPostSubmit,
super.key,
});
final TimelinePost timelinePost;
final TimelineOptions options;
final TimelineService service;
final void Function(TimelinePost) onPostSubmit;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(options.translations.postOverview),
),
body: Column(
children: [
Flexible(
child: TimelinePostScreen(
userId: timelinePost.creatorId,
options: options,
post: timelinePost,
onPostDelete: () {},
service: service,
),
),
Padding(
padding: const EdgeInsets.only(bottom: 30.0),
child: ElevatedButton(
onPressed: () {
onPostSubmit(timelinePost);
},
child: Text(
'${options.translations.postIn} ${timelinePost.category}',
),
),
),
],
),
);
}
}

View file

@ -4,7 +4,7 @@
name: flutter_timeline_view
description: Visual elements of the Flutter Timeline Component
version: 2.0.0
version: 2.1.0
publish_to: none
@ -23,7 +23,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_interface
ref: 2.0.0
ref: 2.1.0
flutter_image_picker:
git:
url: https://github.com/Iconica-Development/flutter_image_picker