swot loading fixed

This commit is contained in:
mohamadmahdi jebeli 2025-07-02 15:20:56 +03:30
parent 75241cf93e
commit 283938d759
3 changed files with 182 additions and 166 deletions

View File

@ -48,9 +48,10 @@ class _MainPageState extends State<MainPage> {
children: [
if (state.stories.isNotEmpty) StorySection(stories: state.stories),
const SizedBox(height: 12),
// محتوای اصلی صفحه
// Main page content
const MainPageMainContent(),
// START: MODIFIED SECTION
Builder(builder: (context) {
final List<Widget> pageContent = [];
if (state.content != null && state.content!.lists.isNotEmpty) {
@ -116,7 +117,7 @@ class _MainPageState extends State<MainPage> {
));
if (currentList.type == 'startup') {
pageContent.add(const _SwotSection());
pageContent.add(_SwotSection(swotItems: state.swotItems));
}
}
}
@ -129,29 +130,15 @@ class _MainPageState extends State<MainPage> {
}
class _SwotSection extends StatelessWidget {
const _SwotSection();
final List<SwotItem> swotItems;
const _SwotSection({required this.swotItems});
@override
Widget build(BuildContext context) {
return FutureBuilder<List<SwotItem>>(
future: SwotService.fetchSwotItems(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox(
height: 10,
);
} else if (snapshot.hasError) {
return const SizedBox(
height: 10,
);
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return const SizedBox(
height: 10,
);
if (swotItems.isEmpty) {
return const SizedBox.shrink();
}
final items = snapshot.data!;
return Padding(
padding: const EdgeInsets.all(0.0),
child: Column(
@ -208,22 +195,20 @@ class _SwotSection extends StatelessWidget {
/// Swot Items Slider
DidvanSlider(
height: 335,
itemCount: items.length,
height: 330,
itemCount: 7,
viewportFraction: 0.65,
itemBuilder: (context, index, realIndex) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SwotItemCard(item: items[index]),
child: SwotItemCard(item: swotItems[index]),
),
),
),
],
),
);
},
);
}
}
@ -307,9 +292,27 @@ class _MainPageSection extends StatelessWidget {
return const SizedBox();
}
// This condition handles the "Soha" module, which should not display the Opportunity/Threat module.
if (list.type == 'delphi') {
return Column(
children: [
Padding(
_buildSectionHeader(context, icon),
_buildSectionSlider(context),
],
);
}
// For all other modules, display as before.
return Column(
children: [
_buildSectionHeader(context, icon),
_buildSectionSlider(context),
],
);
}
Padding _buildSectionHeader(BuildContext context, IconData? icon) {
return Padding(
padding: const EdgeInsets.only(
left: 16,
right: 16,
@ -347,23 +350,12 @@ class _MainPageSection extends StatelessWidget {
)
],
),
),
if (list.type != 'podcast')
DidvanSlider(
height: 260 +
(_maxSublistCount() - (list.type == 'radar' ? 1 : 0)) * 20,
itemCount: list.contents.length,
viewportFraction: 0.65,
itemBuilder: (context, index, realIndex) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: MainPageGeneralItem(
content: list.contents[index],
type: list.type,
),
),
),
if (list.type == 'podcast')
Padding(
);
}
Widget _buildSectionSlider(BuildContext context) {
if (list.type == 'podcast') {
return Padding(
padding: const EdgeInsets.only(top: 28),
child: Column(
children: list.contents
@ -381,8 +373,20 @@ class _MainPageSection extends StatelessWidget {
)
.toList(),
),
);
}
return DidvanSlider(
height: 260 + (_maxSublistCount() - (list.type == 'radar' ? 1 : 0)) * 20,
itemCount: list.contents.length,
viewportFraction: 0.65,
itemBuilder: (context, index, realIndex) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: MainPageGeneralItem(
content: list.contents[index],
type: list.type,
),
),
],
);
}
}

View File

@ -1,6 +1,7 @@
import 'package:didvan/main.dart';
import 'package:didvan/models/enums.dart';
import 'package:didvan/models/home_page_content/home_page_content.dart';
import 'package:didvan/models/home_page_content/swot.dart';
import 'package:didvan/models/requests/infography.dart';
import 'package:didvan/models/requests/news.dart';
import 'package:didvan/models/requests/radar.dart';
@ -11,6 +12,7 @@ import 'package:didvan/services/app_initalizer.dart';
import 'package:didvan/services/network/request.dart';
import 'package:didvan/services/network/request_helper.dart';
import 'package:didvan/services/story_service.dart';
import 'package:didvan/services/swot_service.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher_string.dart';
@ -18,6 +20,7 @@ class MainPageState extends CoreProvier {
MainPageContent? content;
int unread = 0;
List<UserStories> stories = [];
List<SwotItem> swotItems = [];
Future<void> _getMainPageContent() async {
final service = RequestService(RequestHelper.mainPageContent);
@ -30,6 +33,14 @@ class MainPageState extends CoreProvier {
}
}
Future<void> _getSwotItems() async { // این متد را اضافه کنید
try {
swotItems = await SwotService.fetchSwotItems();
} catch (e) {
// در صورت بروز خطا، میتوانید اینجا آن را مدیریت کنید
}
}
Future<void> _fetchStories() async {
try {
stories = await StoryService.getStories();
@ -47,6 +58,7 @@ class MainPageState extends CoreProvier {
await Future.wait([
_getMainPageContent(),
_fetchStories(),
_getSwotItems(),
]);
appState = AppState.idle;
} catch (e) {

View File

@ -387,13 +387,13 @@ class _UserInfo extends StatelessWidget {
fontWeight: FontWeight.w600,
),
),
DidvanText(
DateTimeUtils.momentGenerator(user.createdAt),
style: const TextStyle(
color: Colors.white70,
fontSize: 14.0,
),
),
// DidvanText(
// DateTimeUtils.momentGenerator(user.createdAt),
// style: const TextStyle(
// color: Colors.white70,
// fontSize: 14.0,
// ),
// ),
],
),
),