我一直在為我的應用程式撰寫 ui,在除錯模式下構建時沒問題。但是當我構建發布 apk 時,UI 被弄臟了,并且沒有顯示文本。小部件未按預期呈現,并且它們的大小未正確呈現。我在不同的手機上檢查過,但結果是一樣的。我的代碼有問題還是顫振的內部錯誤?有沒有人見過這個?
它在發布 apk 中
它在除錯 apk 中
import 'package:cached_network_image/cached_network_image.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:rx_shared_preferences/rx_shared_preferences.dart';
@override
Widget build(BuildContext context) {
return ListView(
children: [
const SizedBox(height: 12.0),
StreamBuilder(
stream: rxPrefs.getStringStream('firstName'),
builder: (context, snapshot) => Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
child: Text(
'${AppLocalizations.of(context)!.hello} ${snapshot.data ?? ''}',
style: AppTextStyles.headline,
),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.h),
child: GestureDetector(
onTap: () => context.push(SearchPage.route),
child: Card(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: [
const Icon(Icons.search),
const SizedBox(width: 12.0),
Text(
AppLocalizations.of(context)!.search,
style: AppTextStyles.title0,
),
],
),
),
),
),
),
FutureBuilder(
future: ApiService.getInstance().getPromos(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Promo> promos = snapshot.data as List<Promo>;
return Padding(
padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 12.h),
child: CarouselSlider.builder(
options: CarouselOptions(
enlargeCenterPage: true,
enableInfiniteScroll: true,
height: widget.mediaQuery.size.height * .25,
viewportFraction: 1,
),
itemCount: promos.length,
itemBuilder: (BuildContext context, int index, int realIndex) => Container(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0)),
clipBehavior: Clip.hardEdge,
height: widget.mediaQuery.size.height * .25,
width: widget.mediaQuery.size.width,
child: CachedNetworkImage(
imageUrl: promos[index].image,
fit: BoxFit.fitWidth,
),
),
),
);
}
return Container(
padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 12.h),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0)),
clipBehavior: Clip.hardEdge,
height: widget.mediaQuery.size.height * .25,
width: widget.mediaQuery.size.width,
// alignment: Alignment.center,
child: const Card(child: Center(child: CircularProgressIndicator())),
);
}),
Padding(
padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 12.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.of(context)!.categories,
style: AppTextStyles.title0,
),
GestureDetector(
onTap: () => context.push(CategoriesPage.route),
child: Text(
AppLocalizations.of(context)!.seeAll,
style: AppTextStyles.title0.copyWith(color: AppColors.grey),
),
),
],
),
),
Consumer<CategoryBloc>(
builder: (context, bloc, child) => SizedBox(
height: widget.mediaQuery.size.height * .2,
child: ListView.builder(
padding: EdgeInsets.only(left: 18.w),
itemCount: bloc.categories.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => CategoryCard(category: bloc.categories[index]),
),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 12.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.of(context)!.popular,
style: AppTextStyles.title0,
),
GestureDetector(
onTap: () => context.push(ProductsPage.route),
child: Text(
AppLocalizations.of(context)!.seeAll,
style: AppTextStyles.title0.copyWith(color: AppColors.grey),
),
),
],
),
),
Consumer<ProductBloc>(
builder: (context, bloc, child) =>
Column(children: bloc.products.take(4).map((e) => ProductWidget(product: e)).toList())),
const SizedBox(height: 16.0),
],
);
}```
uj5u.com熱心網友回復:
const我找到了解決方案,由于基于類的小部件的建構式,小部件沒有呈現。要解決此問題,有兩種方法,第一種是const在小部件建構式和使用之前洗掉,第二種是洗掉screen_util或另一個動態生成值的包。這是我找到原始解決方案的鏈接https://github.com/OpenFlutter/flutter_screenutil/issues/341。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/443140.html
上一篇:接近提示影像標簽更改可見不起作用
