fix styles on the add card page, move the parser to a separate file, change the styles of the page of one news item, add a parser for the subscription page, add the input field for the qr code
This commit is contained in:
@@ -6,6 +6,7 @@ class Subscription {
|
|||||||
final String title;
|
final String title;
|
||||||
final String shortDescription;
|
final String shortDescription;
|
||||||
final String fullDescription;
|
final String fullDescription;
|
||||||
|
final String fullDescriptionJson;
|
||||||
final int planId;
|
final int planId;
|
||||||
final bool isActive;
|
final bool isActive;
|
||||||
final bool isCurrent;
|
final bool isCurrent;
|
||||||
@@ -22,6 +23,7 @@ class Subscription {
|
|||||||
required this.title,
|
required this.title,
|
||||||
required this.shortDescription,
|
required this.shortDescription,
|
||||||
required this.fullDescription,
|
required this.fullDescription,
|
||||||
|
required this.fullDescriptionJson,
|
||||||
required this.planId,
|
required this.planId,
|
||||||
required this.isActive,
|
required this.isActive,
|
||||||
required this.currency,
|
required this.currency,
|
||||||
@@ -43,6 +45,7 @@ class Subscription {
|
|||||||
title: json['title'] ?? '',
|
title: json['title'] ?? '',
|
||||||
shortDescription: json['shortDescription'] ?? '',
|
shortDescription: json['shortDescription'] ?? '',
|
||||||
fullDescription: json['fullDescription'] ?? '',
|
fullDescription: json['fullDescription'] ?? '',
|
||||||
|
fullDescriptionJson: json['fullDescriptionJson'] ?? '',
|
||||||
planId: json['planId'] ?? 0,
|
planId: json['planId'] ?? 0,
|
||||||
isActive: json['isActive'] ?? false,
|
isActive: json['isActive'] ?? false,
|
||||||
currency: currencyData['currency'] ?? 'BYN',
|
currency: currencyData['currency'] ?? 'BYN',
|
||||||
|
|||||||
244
lib/presentation/components/content_parser.dart
Normal file
244
lib/presentation/components/content_parser.dart
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:html/parser.dart' as html_parser;
|
||||||
|
import 'package:html/dom.dart' as dom;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
/// Парсер контента новостей (поддерживает HTML и JSON-формат)
|
||||||
|
class ContentParser {
|
||||||
|
|
||||||
|
/// Парсит текст новости: сначала проверяет textJson, потом text
|
||||||
|
static List<Widget> parseContent({String? textJson, String? text}) {
|
||||||
|
if (textJson != null && textJson.isNotEmpty) {
|
||||||
|
return _parseJsonText(textJson);
|
||||||
|
} else if (text != null && text.isNotEmpty) {
|
||||||
|
return _parseHtmlText(text);
|
||||||
|
}
|
||||||
|
return const [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 HTML-парсинг
|
||||||
|
static List<Widget> _parseHtmlText(String htmlText) {
|
||||||
|
final parsedHtml = html_parser.parse(htmlText);
|
||||||
|
final List<dom.Node> elements = parsedHtml.body?.nodes ?? [];
|
||||||
|
return _parseHtmlElements(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Widget> _parseHtmlElements(List<dom.Node> nodes) {
|
||||||
|
List<Widget> widgets = [];
|
||||||
|
|
||||||
|
for (final node in nodes) {
|
||||||
|
if (node is dom.Element) {
|
||||||
|
final text = node.text.trim();
|
||||||
|
if (text.isEmpty) continue;
|
||||||
|
|
||||||
|
switch (node.localName) {
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
widgets.add(_buildHeader(text));
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
widgets.add(_buildParagraph(text));
|
||||||
|
break;
|
||||||
|
case 'ul':
|
||||||
|
widgets.add(_buildUnorderedList(node.nodes));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
widgets.add(_buildDefaultText(text));
|
||||||
|
}
|
||||||
|
} else if (node is dom.Text) {
|
||||||
|
final text = node.text.trim();
|
||||||
|
if (text.isNotEmpty) {
|
||||||
|
widgets.add(_buildDefaultText(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 JSON-парсинг
|
||||||
|
static List<Widget> _parseJsonText(String jsonString) {
|
||||||
|
try {
|
||||||
|
final dynamic data = jsonDecode(jsonString);
|
||||||
|
return _parseJsonNode(data);
|
||||||
|
} catch (e) {
|
||||||
|
return [
|
||||||
|
const Text(
|
||||||
|
'Ошибка отображения текста новости',
|
||||||
|
style: TextStyle(color: Colors.red, fontSize: 14),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Widget> _parseJsonNode(dynamic node) {
|
||||||
|
List<Widget> widgets = [];
|
||||||
|
|
||||||
|
if (node is List) {
|
||||||
|
for (final item in node) {
|
||||||
|
widgets.addAll(_parseJsonNode(item));
|
||||||
|
}
|
||||||
|
} else if (node is Map<String, dynamic>) {
|
||||||
|
final type = node['type'] as String?;
|
||||||
|
final content = node['content'];
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'div':
|
||||||
|
if (content is List) {
|
||||||
|
widgets.addAll(_parseJsonNode(content));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
final text = _extractJsonText(content);
|
||||||
|
if (text != null && text.isNotEmpty) {
|
||||||
|
widgets.add(_buildHeader(text));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
final text = _extractJsonText(content);
|
||||||
|
if (text != null && text.isNotEmpty) {
|
||||||
|
widgets.add(_buildParagraph(text));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'ul':
|
||||||
|
if (content is List) {
|
||||||
|
widgets.add(_buildJsonUnorderedList(content));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'li':
|
||||||
|
final text = _extractJsonText(content);
|
||||||
|
if (text != null && text.isNotEmpty) {
|
||||||
|
widgets.add(_buildListItem(text));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
final text = _extractJsonText(content);
|
||||||
|
if (text != null && text.isNotEmpty) {
|
||||||
|
widgets.add(_buildDefaultText(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Вспомогательные методы извлечения текста из JSON
|
||||||
|
static String? _extractJsonText(dynamic content) {
|
||||||
|
if (content == null) return null;
|
||||||
|
if (content is List) {
|
||||||
|
return content.map((e) => e?.toString() ?? '').where((s) => s.isNotEmpty).join(' ');
|
||||||
|
}
|
||||||
|
return content.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Виджеты для отображения (принимают НЕ nullable String)
|
||||||
|
static Widget _buildHeader(String text) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Text(
|
||||||
|
text, // ✅ text — не nullable
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildParagraph(String text) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
child: Text(
|
||||||
|
text,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 14,
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildDefaultText(String text) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
child: Text(
|
||||||
|
text,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildUnorderedList(List<dom.Node> children) {
|
||||||
|
final items = <Widget>[];
|
||||||
|
for (final child in children) {
|
||||||
|
if (child is dom.Element && child.localName == 'li') {
|
||||||
|
final text = child.text.trim();
|
||||||
|
if (text.isNotEmpty) {
|
||||||
|
items.add(_buildListItem(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: items,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildJsonUnorderedList(List<dynamic> content) {
|
||||||
|
final items = <Widget>[];
|
||||||
|
for (final item in content) {
|
||||||
|
if (item is Map<String, dynamic> && item['type'] == 'li') {
|
||||||
|
final text = _extractJsonText(item['content']);
|
||||||
|
if (text != null && text.isNotEmpty) {
|
||||||
|
items.add(_buildListItem(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: items,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildListItem(String text) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 16, top: 4, bottom: 4),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const Text('• ',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 14,
|
||||||
|
)),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
text,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 14,
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,7 @@ class SubscriptionCard extends StatelessWidget {
|
|||||||
subscription.shortDescription,
|
subscription.shortDescription,
|
||||||
style: TextStyle(color: Colors.white.withOpacity(0.7), fontSize: 14),
|
style: TextStyle(color: Colors.white.withOpacity(0.7), fontSize: 14),
|
||||||
),
|
),
|
||||||
|
Spacer(),
|
||||||
if (isActive && expiredAt != null) ...[
|
if (isActive && expiredAt != null) ...[
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Builder(
|
Builder(
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class AddCardScreen extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
body: BlocListener<AddCardBloc, AddCardState>(
|
body: BlocListener<AddCardBloc, AddCardState>(
|
||||||
listenWhen: (previous, current) {
|
listenWhen: (previous, current) {
|
||||||
print(
|
print(
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:html/parser.dart' as html_parser;
|
|
||||||
import 'package:html/dom.dart' as dom;
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:be_happy/di/service_locator.dart';
|
import 'package:be_happy/di/service_locator.dart';
|
||||||
import '../../core/app_colors.dart';
|
import '../../core/app_colors.dart';
|
||||||
import '../components/custom_app_bar.dart';
|
import '../components/custom_app_bar.dart';
|
||||||
|
import '../components/content_parser.dart';
|
||||||
import '../../domain/usecase/get_news_by_id_usecase.dart';
|
import '../../domain/usecase/get_news_by_id_usecase.dart';
|
||||||
|
|
||||||
class NewsDetailScreen extends StatefulWidget {
|
class NewsDetailScreen extends StatefulWidget {
|
||||||
@@ -126,258 +124,17 @@ class _NewsDetailScreenState extends State<NewsDetailScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
// ✅ Используем вынесенный парсер
|
||||||
// Текст новости: сначала проверяем textJson, потом text
|
...ContentParser.parseContent(
|
||||||
if (news.textJson != null)
|
textJson: news.textJson,
|
||||||
..._parseJsonText(news.textJson)
|
text: news.text,
|
||||||
else if (news.text != null)
|
),
|
||||||
..._parseHtmlText(news.text),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _parseHtmlText(String htmlText) {
|
// 🔹 Удалены старые методы: _parseHtmlText, _parseHtmlElements, _parseJsonText, _parseJsonNode
|
||||||
final parsedHtml = html_parser.parse(htmlText);
|
|
||||||
final List<dom.Node> elements = parsedHtml.body?.nodes ?? [];
|
|
||||||
|
|
||||||
return _parseHtmlElements(elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> _parseHtmlElements(List<dom.Node> nodes) {
|
|
||||||
List<Widget> widgets = [];
|
|
||||||
|
|
||||||
for (final node in nodes) {
|
|
||||||
if (node is dom.Element) {
|
|
||||||
switch (node.localName) {
|
|
||||||
case 'h1':
|
|
||||||
case 'h2':
|
|
||||||
case 'h3':
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
child: Text(
|
|
||||||
node.text,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Text(
|
|
||||||
node.text,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case 'ul':
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: node.children
|
|
||||||
.where((element) => element is dom.Element && element.localName == 'li')
|
|
||||||
.map((dom.Element li) => Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 16, top: 4, bottom: 4),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Text('• ',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
)),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
li.text,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Text(
|
|
||||||
node.text,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (node is dom.Text) {
|
|
||||||
widgets.add(
|
|
||||||
Text(
|
|
||||||
node.text,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return widgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 🔹 Парсинг JSON-текста (новый метод)
|
|
||||||
List<Widget> _parseJsonText(String jsonString) {
|
|
||||||
try {
|
|
||||||
final dynamic data = jsonDecode(jsonString);
|
|
||||||
return _parseJsonNode(data);
|
|
||||||
} catch (e) {
|
|
||||||
return [
|
|
||||||
const Text(
|
|
||||||
'Ошибка отображения текста новости',
|
|
||||||
style: TextStyle(color: Colors.red, fontSize: 14),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> _parseJsonNode(dynamic node) {
|
|
||||||
List<Widget> widgets = [];
|
|
||||||
|
|
||||||
if (node is List) {
|
|
||||||
// Если корень — массив, парсим каждый элемент
|
|
||||||
for (final item in node) {
|
|
||||||
widgets.addAll(_parseJsonNode(item));
|
|
||||||
}
|
|
||||||
} else if (node is Map<String, dynamic>) {
|
|
||||||
final type = node['type'] as String?;
|
|
||||||
final content = node['content'];
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'div':
|
|
||||||
if (content is List) {
|
|
||||||
widgets.addAll(_parseJsonNode(content));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'h2':
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
child: Text(
|
|
||||||
(content is List)
|
|
||||||
? content.join(' ')
|
|
||||||
: content?.toString() ?? '',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Text(
|
|
||||||
(content is List)
|
|
||||||
? content.join(' ')
|
|
||||||
: content?.toString() ?? '',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case 'ul':
|
|
||||||
if (content is List) {
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: content
|
|
||||||
.where((item) => item is Map<String, dynamic>)
|
|
||||||
.map((item) => item as Map<String, dynamic>)
|
|
||||||
.where((item) => item['type'] == 'li')
|
|
||||||
.map((li) => Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 16, top: 4, bottom: 4),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Text('• ',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
)),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
(li['content'] is List)
|
|
||||||
? li['content'].join(' ')
|
|
||||||
: li['content']?.toString() ?? '',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Если тип неизвестен, просто выводим текст
|
|
||||||
widgets.add(
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Text(
|
|
||||||
(content is List)
|
|
||||||
? content.join(' ')
|
|
||||||
: content?.toString() ?? type ?? 'unknown',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return widgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
String _formatDate(DateTime? date) {
|
String _formatDate(DateTime? date) {
|
||||||
if (date == null) return '';
|
if (date == null) return '';
|
||||||
|
|||||||
@@ -58,27 +58,10 @@ class _PromoCodeScreenContentState extends State<_PromoCodeScreenContent> {
|
|||||||
BlocListener<PromoCodeBloc, PromoCodeState>(
|
BlocListener<PromoCodeBloc, PromoCodeState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state.status == PromoCodeStatus.success) {
|
if (state.status == PromoCodeStatus.success) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
'Промокод активирован! Баланс: ${state.newBalance?.toStringAsFixed(2)} BYN',
|
|
||||||
),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Очищаем поле визуально
|
|
||||||
promoController.clear();
|
promoController.clear();
|
||||||
// Ждем чуть меньше, чтобы пользователь увидел успех
|
Future.delayed(const Duration(milliseconds: 800), () {
|
||||||
Future.delayed(const Duration(milliseconds: 1200), () {
|
|
||||||
if (mounted) Navigator.pop(context);
|
if (mounted) Navigator.pop(context);
|
||||||
});
|
});
|
||||||
} else if (state.status == PromoCodeStatus.failure) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(state.errorMessage ?? 'Ошибка активации'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: BlocBuilder<PromoCodeBloc, PromoCodeState>(
|
child: BlocBuilder<PromoCodeBloc, PromoCodeState>(
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class _ScooterCodeInputScreenState extends State<ScooterCodeInputScreen> {
|
|||||||
|
|
||||||
TextField(
|
TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.text,
|
||||||
maxLength: 7,
|
maxLength: 7,
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 18),
|
style: const TextStyle(color: Colors.white, fontSize: 18),
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import 'package:go_router/go_router.dart';
|
|||||||
|
|
||||||
import '../../core/app_colors.dart';
|
import '../../core/app_colors.dart';
|
||||||
import '../components/app_checkbox.dart';
|
import '../components/app_checkbox.dart';
|
||||||
import '../components/custom_app_bar.dart'; // ✅ Добавь импорт
|
import '../components/custom_app_bar.dart';
|
||||||
import '../components/gradient_button.dart';
|
import '../components/gradient_button.dart';
|
||||||
import '../components/period_selector.dart';
|
import '../components/period_selector.dart';
|
||||||
|
import '../components/content_parser.dart'; // ✅ Парсер контента
|
||||||
import '../event/subscription_details_event.dart';
|
import '../event/subscription_details_event.dart';
|
||||||
import '../state/susbcription_details_state.dart';
|
import '../state/susbcription_details_state.dart';
|
||||||
import '../viewmodel/susbcription_details_bloc.dart';
|
import '../viewmodel/susbcription_details_bloc.dart';
|
||||||
@@ -27,26 +28,25 @@ class SubscriptionDetailsScreen extends StatelessWidget {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
child:
|
child: BlocConsumer<
|
||||||
BlocConsumer<
|
SubscriptionDetailsBloc,
|
||||||
SubscriptionDetailsBloc,
|
SubscriptionDetailsState
|
||||||
SubscriptionDetailsState
|
>(
|
||||||
>(
|
listenWhen: (previous, current) =>
|
||||||
listenWhen: (previous, current) =>
|
current is DetailsContentState && current.isSuccess,
|
||||||
current is DetailsContentState && current.isSuccess,
|
listener: (context, state) {
|
||||||
listener: (context, state) {
|
if (state is DetailsContentState && state.isSuccess) {
|
||||||
if (state is DetailsContentState && state.isSuccess) {
|
context.pop(true);
|
||||||
context.pop(true);
|
}
|
||||||
}
|
},
|
||||||
},
|
builder: (context, state) {
|
||||||
builder: (context, state) {
|
String title = "Загрузка...";
|
||||||
String title = "Загрузка...";
|
if (state is DetailsContentState) {
|
||||||
if (state is DetailsContentState) {
|
title = state.subscription.title;
|
||||||
title = state.subscription.title;
|
}
|
||||||
}
|
return CustomAppBar(title: title);
|
||||||
return CustomAppBar(title: title);
|
},
|
||||||
},
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
@@ -65,8 +65,8 @@ class SubscriptionDetailsScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
BlocBuilder<
|
BlocBuilder<
|
||||||
SubscriptionDetailsBloc,
|
SubscriptionDetailsBloc,
|
||||||
SubscriptionDetailsState
|
SubscriptionDetailsState
|
||||||
>(
|
>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is DetailsLoading) {
|
if (state is DetailsLoading) {
|
||||||
@@ -102,27 +102,26 @@ class SubscriptionDetailsScreen extends StatelessWidget {
|
|||||||
|
|
||||||
Widget _buildContent(BuildContext context, DetailsContentState state) {
|
Widget _buildContent(BuildContext context, DetailsContentState state) {
|
||||||
final bool isAvailableForPurchase = state.subscription.isActive;
|
final bool isAvailableForPurchase = state.subscription.isActive;
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// 🔹 Обёртка для растягивания контента на всю ширину
|
||||||
state.subscription.fullDescription,
|
Column(
|
||||||
style: const TextStyle(
|
crossAxisAlignment: CrossAxisAlignment.stretch, // ✅ Растягивает детей на всю ширину
|
||||||
color: Colors.white,
|
mainAxisSize: MainAxisSize.min, // ✅ Не занимает лишнее место по вертикали
|
||||||
fontSize: 15,
|
children: ContentParser.parseContent(
|
||||||
height: 1.5,
|
textJson: state.subscription.fullDescriptionJson,
|
||||||
|
text: state.subscription.fullDescription,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (isAvailableForPurchase) ...[
|
if (isAvailableForPurchase) ...[
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
|
|
||||||
_ActionCard(state: state),
|
_ActionCard(state: state),
|
||||||
|
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
|
|
||||||
GradientButton(
|
GradientButton(
|
||||||
text: state.isAlreadyPurchased ? 'Продлить' : 'Активировать',
|
text: state.isAlreadyPurchased ? 'Продлить' : 'Активировать',
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@@ -255,4 +254,4 @@ class _PriceRow extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,11 +60,16 @@ class SubscriptionsListScreen extends StatelessWidget {
|
|||||||
final clientSub = clientSubsMap[subscription.id];
|
final clientSub = clientSubsMap[subscription.id];
|
||||||
final DateTime? expirationDate = isPurchased ? clientSub?.expiredAt : null;
|
final DateTime? expirationDate = isPurchased ? clientSub?.expiredAt : null;
|
||||||
|
|
||||||
return SubscriptionCard(
|
return SizedBox(
|
||||||
subscription: subscription,
|
height: 230, //
|
||||||
isActive: isPurchased,
|
child: SubscriptionCard(
|
||||||
expiredAt: expirationDate,
|
subscription: subscription,
|
||||||
onRefresh: () { context.read<SubscriptionListBloc>().add(LoadSubscriptionsEvent());},
|
isActive: isPurchased,
|
||||||
|
expiredAt: expirationDate,
|
||||||
|
onRefresh: () {
|
||||||
|
context.read<SubscriptionListBloc>().add(LoadSubscriptionsEvent());
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user