swot loading fixed
This commit is contained in:
parent
75241cf93e
commit
283938d759
|
|
@ -48,9 +48,10 @@ class _MainPageState extends State<MainPage> {
|
||||||
children: [
|
children: [
|
||||||
if (state.stories.isNotEmpty) StorySection(stories: state.stories),
|
if (state.stories.isNotEmpty) StorySection(stories: state.stories),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
// محتوای اصلی صفحه
|
// Main page content
|
||||||
const MainPageMainContent(),
|
const MainPageMainContent(),
|
||||||
|
|
||||||
|
// START: MODIFIED SECTION
|
||||||
Builder(builder: (context) {
|
Builder(builder: (context) {
|
||||||
final List<Widget> pageContent = [];
|
final List<Widget> pageContent = [];
|
||||||
if (state.content != null && state.content!.lists.isNotEmpty) {
|
if (state.content != null && state.content!.lists.isNotEmpty) {
|
||||||
|
|
@ -116,7 +117,7 @@ class _MainPageState extends State<MainPage> {
|
||||||
));
|
));
|
||||||
|
|
||||||
if (currentList.type == 'startup') {
|
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 {
|
class _SwotSection extends StatelessWidget {
|
||||||
const _SwotSection();
|
final List<SwotItem> swotItems;
|
||||||
|
const _SwotSection({required this.swotItems});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<List<SwotItem>>(
|
if (swotItems.isEmpty) {
|
||||||
future: SwotService.fetchSwotItems(),
|
return const SizedBox.shrink();
|
||||||
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,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final items = snapshot.data!;
|
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(0.0),
|
padding: const EdgeInsets.all(0.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
@ -208,22 +195,20 @@ class _SwotSection extends StatelessWidget {
|
||||||
|
|
||||||
/// Swot Items Slider
|
/// Swot Items Slider
|
||||||
DidvanSlider(
|
DidvanSlider(
|
||||||
height: 335,
|
height: 330,
|
||||||
itemCount: items.length,
|
itemCount: 7,
|
||||||
viewportFraction: 0.65,
|
viewportFraction: 0.65,
|
||||||
itemBuilder: (context, index, realIndex) => Padding(
|
itemBuilder: (context, index, realIndex) => Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0.0),
|
padding: const EdgeInsets.symmetric(horizontal: 0.0),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
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();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This condition handles the "Soha" module, which should not display the Opportunity/Threat module.
|
||||||
|
if (list.type == 'delphi') {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
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(
|
padding: const EdgeInsets.only(
|
||||||
left: 16,
|
left: 16,
|
||||||
right: 16,
|
right: 16,
|
||||||
|
|
@ -347,23 +350,12 @@ class _MainPageSection extends StatelessWidget {
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
if (list.type != 'podcast')
|
}
|
||||||
DidvanSlider(
|
|
||||||
height: 260 +
|
Widget _buildSectionSlider(BuildContext context) {
|
||||||
(_maxSublistCount() - (list.type == 'radar' ? 1 : 0)) * 20,
|
if (list.type == 'podcast') {
|
||||||
itemCount: list.contents.length,
|
return Padding(
|
||||||
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(
|
|
||||||
padding: const EdgeInsets.only(top: 28),
|
padding: const EdgeInsets.only(top: 28),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: list.contents
|
children: list.contents
|
||||||
|
|
@ -381,8 +373,20 @@ class _MainPageSection extends StatelessWidget {
|
||||||
)
|
)
|
||||||
.toList(),
|
.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,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:didvan/main.dart';
|
import 'package:didvan/main.dart';
|
||||||
import 'package:didvan/models/enums.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/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/infography.dart';
|
||||||
import 'package:didvan/models/requests/news.dart';
|
import 'package:didvan/models/requests/news.dart';
|
||||||
import 'package:didvan/models/requests/radar.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.dart';
|
||||||
import 'package:didvan/services/network/request_helper.dart';
|
import 'package:didvan/services/network/request_helper.dart';
|
||||||
import 'package:didvan/services/story_service.dart';
|
import 'package:didvan/services/story_service.dart';
|
||||||
|
import 'package:didvan/services/swot_service.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
|
|
@ -18,6 +20,7 @@ class MainPageState extends CoreProvier {
|
||||||
MainPageContent? content;
|
MainPageContent? content;
|
||||||
int unread = 0;
|
int unread = 0;
|
||||||
List<UserStories> stories = [];
|
List<UserStories> stories = [];
|
||||||
|
List<SwotItem> swotItems = [];
|
||||||
|
|
||||||
Future<void> _getMainPageContent() async {
|
Future<void> _getMainPageContent() async {
|
||||||
final service = RequestService(RequestHelper.mainPageContent);
|
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 {
|
Future<void> _fetchStories() async {
|
||||||
try {
|
try {
|
||||||
stories = await StoryService.getStories();
|
stories = await StoryService.getStories();
|
||||||
|
|
@ -47,6 +58,7 @@ class MainPageState extends CoreProvier {
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
_getMainPageContent(),
|
_getMainPageContent(),
|
||||||
_fetchStories(),
|
_fetchStories(),
|
||||||
|
_getSwotItems(),
|
||||||
]);
|
]);
|
||||||
appState = AppState.idle;
|
appState = AppState.idle;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
|
|
@ -387,13 +387,13 @@ class _UserInfo extends StatelessWidget {
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
DidvanText(
|
// DidvanText(
|
||||||
DateTimeUtils.momentGenerator(user.createdAt),
|
// DateTimeUtils.momentGenerator(user.createdAt),
|
||||||
style: const TextStyle(
|
// style: const TextStyle(
|
||||||
color: Colors.white70,
|
// color: Colors.white70,
|
||||||
fontSize: 14.0,
|
// fontSize: 14.0,
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue