رونمایی از پخته‌ترین و کاربردی‌ترین محصولات آموزشی سون‌لرن با کلی آفرهای ویژه🔥
۰ ثانیه
۰ دقیقه
۰ ساعت
۱ هستی نباتی
theme.of(context)
محسن موحد حل شده توسط محسن موحد

سلام 

من وقتی میخوام تو تکستم از text theme استفاده کنم بهم ارور میده

      textTheme: GoogleFonts.latoTextTheme(TextTheme(
          bodyMedium: TextStyle(fontSize: 15),
          bodyLarge: TextStyle(fontSize: 13),
          titleLarge: TextStyle(fontWeight: FontWeight.bold),
          titleMedium: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
        )),

این قسمت themedata و کد text که قسمت style:theme.of(context) رو ارور میده

 const Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'david efron',
                      style: theme.of(context).textTheme.titleMedium,
                    ),
                    SizedBox(
                      height: 2,
                    ),
                    Text('application developer'),
                    SizedBox(
                      height: 4,
                    ),
                    Row(
                      children: [
                        Icon(CupertinoIcons.location_circle),
                        Text(
                          'amsterdam , netherlands',
                          style: theme.of(context).TextTheme.bodyLarge,
                        ),
                      ],                  

سلام،

1. theme.of(context) باید Theme.of(context) باشد. (T باید بزرگ باشد)
2. برای دسترسی به TextTheme, باید از .textTheme استفاده کنید، نه .TextTheme (t باید کوچک باشد).
در نتیجه، کد شما باید به شکل زیر باشد:

Text(
 'david efron',
 style: Theme.of(context).textTheme.titleMedium,
),
SizedBox(
 height: 2,
),
Text('application developer'),
SizedBox(
 height: 4,
),
Row(
 children: [
   Icon(CupertinoIcons.location_circle),
   Text(
     'amsterdam , netherlands',
     style: Theme.of(context).textTheme.bodyLarge,
   ),
 ],
)
بهترین پاسخ
محسن موحد ۰۴ فروردین ۱۴۰۳، ۰۹:۱۰