将MediaQuery textScaleFactor与VR外包装颤动一起使用



我想在我的应用程序中使用textScaleFactor,并且必须在MaterialApp中使用,并且我使用VRouter包,有办法将其与此包一起使用吗

class MyApp extends StatelessWidget {
Future<void> authenticationCheck(BuildContext context,
{VRedirector vRedirector}) async {
if (userRepo.currentUser.value.auth != true) {
// ignore: deprecated_member_use
vRedirector.push('/login',
queryParameters: {'redirectedFrom': '${vRedirector.to}'});
}
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: settingRepo.setting,
builder: (context, Setting _setting, _) {
return VRouter(
title: 'Ta3mer Vendor',
locale: _setting.mobileLanguage.value,
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
theme: _setting.brightness.value == Brightness.light
? ThemeData(
fontFamily: 'proximanova-regular',
primaryColor: Colors.white,
disabledColor: Colors.grey,
cardColor: Colors.white,
secondaryHeaderColor: Color(0xFF043832).withOpacity(1.0),
brightness: Brightness.light,
colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: Color(0xFF180968)),
primaryColorLight: Colors.white,
backgroundColor: Colors.black,
dividerColor: Color(0xFF8c98a8).withOpacity(0.1),
focusColor: Color(0xFF8c98a8).withOpacity(1.0),
primaryColorDark: Color(0xFF180968),
textTheme: TextTheme(
headline5: TextStyle(
fontSize: 22.0,
color: Color(0xFF043832).withOpacity(1.0),
height: 1.3),
headline4: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w700,
color: Color(0xFF043832).withOpacity(1.0),
height: 1.3),
headline3: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w700,
color: Color(0xFF043832).withOpacity(1.0),
height: 1.3),
headline2: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w700,
color: Color(0xFF180968).withOpacity(1.0),
height: 1.4),
headline1: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w700,
color: Color(0xFF043832).withOpacity(1.0),
height: 1.4),
subtitle1: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.w600,
color: Colors.black,
height: 1.3),
subtitle2: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w300,
color: Color(0xFF043832).withOpacity(1.0),
height: 1.2),
headline6: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w700,
color: Color(0xFF180968).withOpacity(1.0),
height: 1.3),
bodyText2: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Colors.black,
height: 1.2),
bodyText1: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: Color(0xFF043832).withOpacity(1.0),
height: 1.3),
caption: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w300,
color: Color(0xFF8c98a8).withOpacity(1.0),
height: 1.7),
),
)
: ThemeData(
fontFamily: 'proximanova-regular',
brightness: Brightness.dark,
scaffoldBackgroundColor: Color(0xFF2C2C2C),
primaryColorLight: Colors.white,
primaryColor: Color(0xFF2C2C2C),
backgroundColor: Color(0xFF9999aa),
colorScheme: Theme.of(context).colorScheme.copyWith(
background: const Color(0xFF000000),
onBackground: const Color(0xFF2e2e2e),
primary: const Color(0xFF6553D9),
onPrimary: const Color(0xFFeeeeee),
brightness: Brightness.dark,
secondary: Color(0xFF180968)),
dividerColor: Color(0xFF9999aa).withOpacity(0.1),
hintColor: Color(0xFFccccdd).withOpacity(0.1),
focusColor: Color(0xFF9999aa).withOpacity(1),
primaryColorDark: Color(0xFF180968),
textTheme: TextTheme(
headline5: TextStyle(
fontSize: 22.0,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.3),
headline4: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w700,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.3),
headline3: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w700,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.3),
headline2: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w700,
color: Color(0xFF180968).withOpacity(1.0),
height: 1.4),
headline1: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w700,
color: Color(0xFFffffff).withOpacity(1),
height: 1.4),
subtitle1: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.w600,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.3),
subtitle2: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w300,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.2),
headline6: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w700,
color: Color(0xFF180968).withOpacity(1.0),
height: 1.3),
bodyText2: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.2),
bodyText1: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: Color(0xFF9999aa).withOpacity(1),
height: 1.3),
caption: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w300,
color: Color(0xFF9999aa).withOpacity(0.6),
height: 1.2),
),
),
debugShowCheckedModeBanner: false,
routes: [
VWidget(path: '/login', widget: HomePage()),
VGuard(
beforeEnter: (vRedirector) =>
authenticationCheck(context, vRedirector: vRedirector),
stackedRoutes: [
VPopHandler(
onPop: (_) async => print('POP'),
stackedRoutes: [
VNester(
path: null,
name: 'VNester1',
widgetBuilder: (child) => MyScaffold(
child,
title: 'VNester1',
),
nestedRoutes: [
VWidget(
path: '/Order',
name: 'Orders',
widget: Orders(),
aliases: ['/Orders'],
),
VWidget(
path: '/takeaway',
name: 'Orders',
widget: OrdersTakeaway(),
aliases: ['/Orders'],
),
VWidget(
path: '/pos_checkout',
name: 'pos_checkout',
widget: PosCheckout(),
aliases: ['/pos_checkout'],
),
VWidget(
path: '/BestSellerMemberShip',
name: 'BestSellerMemberShip',
widget: BestSellerMembership(),
aliases: ['/BestSellerMemberShip'],
),
VWidget(
path: '/ReturnOrder',
name: 'ReturnOrder',
widget: ReturnOrder(),
aliases: ['/ReturnOrder'],
),
VWidget(
path: '/wallet',
name: 'wallet',
widget: WalletWidget(),
aliases: ['/wallet'],
),
VWidget(
path: '/coupon',
name: 'coupon',
widget: CouponPage(),
aliases: ['/coupon'],
),
VWidget(
path: '/productlist',
name: 'productlist',
widget: ProductList(),
aliases: ['/productlist'],
),
VWidget(
path: '/itemlist',
name: 'itemlist',
widget: RTypeProductList(),
aliases: ['/itemlist'],
),
VWidget(
path: '/add_product',
name: 'add_product',
widget: AddProduct(),
aliases: ['/add_product'],
),
VWidget(
path: '/add_item',
name: 'add_item',
widget: AddItem(),
aliases: ['/add_item'],
),
VWidget(
path: '/deliverytimeslot',
name: 'deliverytimrslot',
widget: DeliveryTimeSlot(),
aliases: ['/add_product'],
),
VWidget(
path: '/vendorlist',
name: 'vendorlist',
widget: VendorList(),
aliases: ['/vendorlist'],
),
VWidget(
path: '/profile',
name: 'profile',
widget: ProfileView(),
aliases: ['/profiledata'],
),
VWidget(
path: '/subcategory',
name: 'subcategory',
widget: SubCategoryPage(),
aliases: ['/subcategory'],
),
VWidget(
path: '/dashboard',
name: 'dashboard',
widget: DashboardWidget(),
aliases: ['/dashboard'],
),
VWidget(
path: '/banner',
name: 'banner',
widget: Banners(),
aliases: ['/banner'],
),
VWidget(
path: '/invoice/:id',
name: 'invoice',
widget: InvoiceWidget(),
aliases: ['/invoice'],
),
VWidget(
path: '/category',
widget: CategoryPage(),
// Custom transition
),
VWidget(
path: '/bulk_upload',
widget: BulkUpload(),
// Custom transition
),
VWidget(
path: '/report',
widget: Report(),
// Custom transition
),
VWidget(
path: '/language',
widget: LanguagesWidget(),
// Custom transition
),
VWidget(
path: '/Barcode',
widget: BarCodePdf(),
// Custom transition
),
VWidget(
path: '/Wallet',
widget: WalletWidget(),
// Custom transition
),
VWidget(
path: '/Pos_Checkout',
widget: PosCheckout(),
// Custom transition
),
VWidget(
path: '/thermalSlip',
widget: Slip(),
// Custom transition
),
],
),
],
),
],
),
VRouteRedirector(
redirectTo: '/login',
path: r':_(.*)',
),
],
);
});
}
}

这是我的主页,应该遵循的方式如下

return MaterialApp(
builder: (context, child) {
return MediaQuery(
child: child,
data: MediaQuery.of(context).copyWith(textScaleFactor: 0.9),
);
},

应用程序完全建立在此包上,不能更改,有解决方案吗

经过一些研究和实验,我找到了这个解决方案

return ValueListenableBuilder(
valueListenable: settingRepo.setting,
builder: (context, Setting _setting, _) {
return VRouter(
builder: (context, child) {
return MediaQuery(
child: child,
data: MediaQuery.of(context).copyWith(textScaleFactor: 0.9),
);
},

只需在VRouter中使用生成器

最新更新