Skip to content

Commit

Permalink
post detail
Browse files Browse the repository at this point in the history
  • Loading branch information
MOKTADIR authored and MOKTADIR committed Mar 19, 2023
1 parent f6dc53a commit ef95295
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 32 deletions.
25 changes: 21 additions & 4 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:get/get.dart';
import 'package:getx_standard/app/modules/home/bindings/home_binding.dart';
import 'package:getx_standard/app/modules/home/views/post_detail_view.dart';

import '../../../service/api_urls.dart';
import '../../../service/base_controller.dart';
Expand All @@ -12,10 +14,8 @@ class HomeController extends GetxController with BaseController {
getPostList() async {
showLoading();

var response = await DioClient().get(url: ApiUrl.allPosts, header: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}).catchError(handleError);
var response = await DioClient()
.get(url: ApiUrl.allPosts, header: {}).catchError(handleError);

if (response == null) return;

Expand All @@ -25,6 +25,23 @@ class HomeController extends GetxController with BaseController {
hideLoading();
}

/// GET POST DETAIL
String title = "";
String body = "";

getPostDetail(int? id) async {
showLoading();
var response = await DioClient().get(
url: "${ApiUrl.postDetail}$id", header: {}).catchError(handleError);

if (response == null) return;

title = response["title"].toString();
body = response["body"].toString();
hideLoading();
Get.to(() => const PostDetailView(), binding: HomeBinding());
}

@override
void onReady() async {
// TODO: implement onReady
Expand Down
32 changes: 19 additions & 13 deletions lib/app/modules/home/views/home_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../../../../config/theme/my_fonts.dart';
import '../../../components/empty_widget.dart';
import '../controllers/home_controller.dart';
Expand Down Expand Up @@ -36,18 +36,24 @@ class HomeView extends GetView<HomeController> {
separatorBuilder: (_, __) => SizedBox(
height: 20.h,
),
itemBuilder: (ctx, index) => Container(
padding: const EdgeInsets.all(5),
width: double.infinity,
color: theme.canvasColor,
child: Center(
child: Text(
controller.postList[index].title ?? "",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: MyFonts.headline6TextSize,
fontWeight: FontWeight.w500,
color: theme.primaryColor,
itemBuilder: (ctx, index) => GestureDetector(
onTap: () async {
await controller
.getPostDetail(controller.postList[index].id);
},
child: Container(
padding: const EdgeInsets.all(5),
width: double.infinity,
color: theme.canvasColor,
child: Center(
child: Text(
controller.postList[index].title ?? "",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: MyFonts.headline6TextSize,
fontWeight: FontWeight.w500,
color: theme.primaryColor,
),
),
),
),
Expand Down
37 changes: 37 additions & 0 deletions lib/app/modules/home/views/post_detail_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../controllers/home_controller.dart';

class PostDetailView extends GetView<HomeController> {
const PostDetailView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Post Detail'),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
controller.title,
style: theme.textTheme.headlineSmall,
),
SizedBox(height: 40.h),
Text(
controller.body,
style: theme.textTheme.bodyLarge,
),
],
),
),
);
}
}
1 change: 1 addition & 0 deletions lib/app/service/api_urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class ApiUrl {
/// Base URL
static const baseUrl = "https://jsonplaceholder.typicode.com";
static const allPosts = "$baseUrl/posts";
static const postDetail = "$baseUrl/posts/";
}
4 changes: 2 additions & 2 deletions lib/config/theme/light_theme_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class LightThemeColors {
static const Color buttonDisabledTextColor = Colors.black;

//TEXT
static const Color bodyTextColor = Colors.black;
static const Color headlinesTextColor = Colors.black;
static const Color bodyTextColor = primaryColor;
static const Color headlinesTextColor = primaryColor;
static const Color captionTextColor = Colors.grey;
static const Color hintTextColor = Color(0xff686868);

Expand Down
25 changes: 12 additions & 13 deletions lib/config/theme/my_styles.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'dark_theme_colors.dart';
import 'my_fonts.dart';
import 'light_theme_colors.dart';
import 'my_fonts.dart';

class MyStyles {
///icons theme
Expand All @@ -20,7 +19,7 @@ class MyStyles {
AppBarTheme(
elevation: 0,
titleTextStyle:
getTextTheme(isLightTheme: isLightTheme).bodyText1!.copyWith(
getTextTheme(isLightTheme: isLightTheme).bodyLarge!.copyWith(
color: Colors.white,
fontSize: MyFonts.appBarTittleSize,
),
Expand All @@ -35,56 +34,56 @@ class MyStyles {

///text theme
static TextTheme getTextTheme({required bool isLightTheme}) => TextTheme(
button:
labelLarge:
MyFonts.buttonTextStyle.copyWith(fontSize: MyFonts.buttonTextSize),
bodyText1: (MyFonts.bodyTextStyle).copyWith(
bodyLarge: (MyFonts.bodyTextStyle).copyWith(
fontWeight: FontWeight.bold,
fontSize: MyFonts.body1TextSize,
color: isLightTheme
? LightThemeColors.bodyTextColor
: DarkThemeColors.bodyTextColor),
bodyText2: (MyFonts.bodyTextStyle).copyWith(
bodyMedium: (MyFonts.bodyTextStyle).copyWith(
fontSize: MyFonts.body2TextSize,
color: isLightTheme
? LightThemeColors.bodyTextColor
: DarkThemeColors.bodyTextColor),
headline1: (MyFonts.headlineTextStyle).copyWith(
displayLarge: (MyFonts.headlineTextStyle).copyWith(
fontSize: MyFonts.headline1TextSize,
fontWeight: FontWeight.bold,
color: isLightTheme
? LightThemeColors.headlinesTextColor
: DarkThemeColors.headlinesTextColor),
headline2: (MyFonts.headlineTextStyle).copyWith(
displayMedium: (MyFonts.headlineTextStyle).copyWith(
fontSize: MyFonts.headline2TextSize,
fontWeight: FontWeight.bold,
color: isLightTheme
? LightThemeColors.headlinesTextColor
: DarkThemeColors.headlinesTextColor),
headline3: (MyFonts.headlineTextStyle).copyWith(
displaySmall: (MyFonts.headlineTextStyle).copyWith(
fontSize: MyFonts.headline3TextSize,
fontWeight: FontWeight.bold,
color: isLightTheme
? LightThemeColors.headlinesTextColor
: DarkThemeColors.headlinesTextColor),
headline4: (MyFonts.headlineTextStyle).copyWith(
headlineMedium: (MyFonts.headlineTextStyle).copyWith(
fontSize: MyFonts.headline4TextSize,
fontWeight: FontWeight.bold,
color: isLightTheme
? LightThemeColors.headlinesTextColor
: DarkThemeColors.headlinesTextColor),
headline5: (MyFonts.headlineTextStyle).copyWith(
headlineSmall: (MyFonts.headlineTextStyle).copyWith(
fontSize: MyFonts.headline5TextSize,
fontWeight: FontWeight.bold,
color: isLightTheme
? LightThemeColors.headlinesTextColor
: DarkThemeColors.headlinesTextColor),
headline6: (MyFonts.headlineTextStyle).copyWith(
titleLarge: (MyFonts.headlineTextStyle).copyWith(
fontSize: MyFonts.headline6TextSize,
fontWeight: FontWeight.bold,
color: isLightTheme
? LightThemeColors.headlinesTextColor
: DarkThemeColors.headlinesTextColor),
caption: TextStyle(
bodySmall: TextStyle(
color: isLightTheme
? LightThemeColors.captionTextColor
: DarkThemeColors.captionTextColor,
Expand Down

0 comments on commit ef95295

Please sign in to comment.