Skip to content

Commit

Permalink
Added Screen to test the get category by id
Browse files Browse the repository at this point in the history
  • Loading branch information
umareko committed Dec 29, 2023
1 parent 05a0e07 commit cf0f988
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/core/route/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,7 @@ class AppRoute {

static const viewStream = 'viewStream';
static const viewStreamRoute = 'viewStream';

static const getCategory = 'getCategory';
static const getCategoryRoute = 'getCategory/:categoryId';
}
6 changes: 6 additions & 0 deletions lib/core/route/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter_social_sample_app/presentation/screen/channel_update/cha
import 'package:flutter_social_sample_app/presentation/screen/chat/chat_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/comment_query/comment_query_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/comment_query_reply/comment_query_reply_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/community_category/community_category_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/community_create/community_create_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/community_feed/community_feed_screen.dart';
import 'package:flutter_social_sample_app/presentation/screen/community_in_review_post_list/community_in_review_post_list_screen.dart';
Expand Down Expand Up @@ -213,6 +214,11 @@ class AppRouter {
path: AppRoute.postDetailRoute,
builder: (context, state) => PostDetailScreen(postId: state.params['postId']!),
),
GoRoute(
name: AppRoute.getCategory,
path: AppRoute.getCategoryRoute,
builder: (context, state) => CommunityCategoryScreen(categoryId: state.params['categoryId']!),
),
GoRoute(
name: AppRoute.createPollPost,
path: AppRoute.createPollPostRoute,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:amity_sdk/amity_sdk.dart';
import 'package:flutter/material.dart';

class CommunityCategoryScreen extends StatefulWidget {
final String categoryId;
const CommunityCategoryScreen({super.key, required this.categoryId});

@override
State<CommunityCategoryScreen> createState() =>
_CommunityCategoryScreenState();
}

class _CommunityCategoryScreenState extends State<CommunityCategoryScreen> {
Future<AmityCommunityCategory>? _future;
@override
void initState() {
_future = AmitySocialClient.newCommunityRepository()
.getCategory(widget.categoryId);
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Community Catergory'),
),
body: SafeArea(
child: FutureBuilder(
future: _future,
builder: ((context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else {
if (snapshot.hasData) {
var category = snapshot.data as AmityCommunityCategory;
return ListTile(
leading: category.avatarId != null
? Image.network(
category.avatar!.fileUrl!,
fit: BoxFit.fill,
)
: Image.asset('assets/user_placeholder.png'),
title: Text(category.name!),
subtitle: Text(category.categoryId!),
);
}

if (snapshot.hasError) {
return Text("Error ${snapshot.error}");
}

return const Text("No Data");
}
}),
),
),
);
}
}
15 changes: 15 additions & 0 deletions lib/presentation/screen/dashboard/dashboar_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ class _DashboardScreenState extends State<DashboardScreen> {
// },
// child: const Text('Create Community'),
// ),
const SizedBox(height: 20),
TextButton(
onPressed: () {
EditTextDialog.show(
context,
hintText: 'Enter Category Id',
onPress: (value) {
GoRouter.of(context).goNamed(AppRoute.getCategory,
params: {'categoryId': value});
},
);
},
child: const Text('Get Category by Id'),
),

const SizedBox(height: 20),
TextButton(
onPressed: () {
Expand Down

0 comments on commit cf0f988

Please sign in to comment.