Fix: shorten text

This commit is contained in:
2024-06-07 14:57:28 +03:00
parent 0170505376
commit 65c8f56e20
7 changed files with 45 additions and 11 deletions

View File

@@ -46,7 +46,8 @@ class OrderConfirmItemCard extends StatelessWidget {
name, name,
style: Theme.of(context).textTheme.bodyLarge, style: Theme.of(context).textTheme.bodyLarge,
), ),
Text('$price руб. x $count = ${price * count} руб.'), Text(
'${price.toStringAsFixed(2)} руб. x $count = ${(price * count).toStringAsFixed(2)} руб.'),
], ],
) )
], ],

View File

@@ -280,7 +280,7 @@ class _BasketPageState extends State<BasketPage> {
final item = cartItems[index]; final item = cartItems[index];
return BasketItemCard( return BasketItemCard(
name: item.title, name: item.title,
price: item.price.toString(), price: item.price.toStringAsFixed(2),
id: item.id, id: item.id,
image: Image( image: Image(
image: NetworkImage(item.images[0].url), image: NetworkImage(item.images[0].url),
@@ -304,7 +304,7 @@ class _BasketPageState extends State<BasketPage> {
child: Column( child: Column(
children: [ children: [
Text( Text(
'Итого: $totalPrice руб.', 'Итого: ${totalPrice.toStringAsFixed(2)} руб.',
), ),
ElevatedButton( ElevatedButton(
onPressed: () => Navigator.of(context).push( onPressed: () => Navigator.of(context).push(

View File

@@ -13,6 +13,7 @@ import 'package:gymlink_module_web/providers/main.dart';
import 'package:gymlink_module_web/tools/items.dart'; import 'package:gymlink_module_web/tools/items.dart';
import 'package:gymlink_module_web/tools/prefs.dart'; import 'package:gymlink_module_web/tools/prefs.dart';
import 'package:gymlink_module_web/tools/routes.dart'; import 'package:gymlink_module_web/tools/routes.dart';
import 'package:gymlink_module_web/tools/text.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@@ -194,7 +195,7 @@ class _DetailPageState extends State<DetailPage> {
appBar: const GymLinkAppBar(), appBar: const GymLinkAppBar(),
body: item != null body: item != null
? Column(mainAxisAlignment: MainAxisAlignment.start, children: [ ? Column(mainAxisAlignment: MainAxisAlignment.start, children: [
GymLinkHeader(title: item!.title), GymLinkHeader(title: shortString(item!.title, length: 20)),
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
child: Padding( child: Padding(
@@ -269,6 +270,14 @@ class _DetailPageState extends State<DetailPage> {
item!.images[0].url, item!.images[0].url,
height: 400, height: 400,
), ),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
item!.title,
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
),
Center( Center(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10), padding: const EdgeInsets.symmetric(vertical: 10),
@@ -333,7 +342,7 @@ class _DetailPageState extends State<DetailPage> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Text(
'Стоимость ${item!.price}руб.', 'Стоимость ${item!.price.toStringAsFixed(2)}руб.',
style: style:
Theme.of(context).textTheme.bodyLarge, Theme.of(context).textTheme.bodyLarge,
), ),

View File

@@ -12,6 +12,7 @@ import 'package:gymlink_module_web/tools/items.dart';
import 'package:gymlink_module_web/tools/prefs.dart'; import 'package:gymlink_module_web/tools/prefs.dart';
import 'package:gymlink_module_web/tools/relative.dart'; import 'package:gymlink_module_web/tools/relative.dart';
import 'package:gymlink_module_web/tools/routes.dart'; import 'package:gymlink_module_web/tools/routes.dart';
import 'package:gymlink_module_web/tools/text.dart';
import 'package:lazy_load_scrollview/lazy_load_scrollview.dart'; import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@@ -251,7 +252,9 @@ class _MainPageState extends State<MainPage> {
child: Scrollbar( child: Scrollbar(
child: ListView( child: ListView(
children: [ children: [
filteredData.isEmpty && searchText != '' && !isSearching filteredData.isEmpty &&
(searchText != '' || selectedCategory != null) &&
!isSearching
? const Center(child: Text('Ничего не найдено')) ? const Center(child: Text('Ничего не найдено'))
: isSearching : isSearching
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
@@ -276,8 +279,8 @@ class _MainPageState extends State<MainPage> {
.image, .image,
width: 50, width: 50,
), ),
name: product.title, name: shortString(product.title),
price: product.price.toString(), price: product.price.toStringAsFixed(2),
onTap: () => Navigator.of(context).push( onTap: () => Navigator.of(context).push(
CustomPageRoute( CustomPageRoute(
builder: (context) => DetailPage( builder: (context) => DetailPage(

View File

@@ -61,6 +61,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
List<GymItem> cartItems = []; List<GymItem> cartItems = [];
double totalPrice = 0; double totalPrice = 0;
List<GymItem> gymCart = []; List<GymItem> gymCart = [];
bool isAgree = false;
bool _isLoading = true; bool _isLoading = true;
@override @override
@@ -107,6 +108,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
: ConstrainedBox( : ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 350), constraints: const BoxConstraints(maxHeight: 350),
child: ListView.builder( child: ListView.builder(
shrinkWrap: true,
itemCount: cartItems.length, itemCount: cartItems.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final item = cartItems[index]; final item = cartItems[index];
@@ -129,7 +131,8 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
Expanded( Expanded(
child: Column( child: Column(
children: [ children: [
MarkdownBody(data: '## Итого: $totalPrice'), MarkdownBody(
data: '## Итого: ${totalPrice.toStringAsFixed(2)} руб.'),
Expanded( Expanded(
child: TextField( child: TextField(
decoration: InputDecoration( decoration: InputDecoration(
@@ -161,6 +164,15 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
), ),
), ),
), ),
CheckboxListTile(
title: const Text('Согласен с обаботкой персональных данных'),
value: isAgree,
onChanged: (value) {
setState(() {
isAgree = value!;
});
},
),
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: () async {
_goToPage(); _goToPage();

View File

@@ -27,8 +27,8 @@ class GymLinkProvider with ChangeNotifier {
// } // }
} }
void changeTheme(int color) { void changeTheme(int color, {bool blackTheme = false}) {
_blackTheme = !_blackTheme; _blackTheme = blackTheme;
_theme = getThemeData(Color(color), _blackTheme); _theme = getThemeData(Color(color), _blackTheme);
notifyListeners(); notifyListeners();
} }

9
lib/tools/text.dart Normal file
View File

@@ -0,0 +1,9 @@
String shortString(String text, {int length = 10}) {
if (text.length > length) {
String shortText = text.substring(0, length);
return shortText +
(text.substring(0, length + 1).endsWith(' ') ? '' : '...');
} else {
return text;
}
}