【问题标题】:'textSelectionHandleColor' is deprecated and shouldn't be used'textSelectionHandleColor' 已弃用,不应使用
【发布时间】:2021-04-03 21:22:13
【问题描述】:

在颤振中,我已经像这样定义了我的自定义主题

ThemeData(
  ...
  textSelectionColor: Colors.black,
  textSelectionHandleColor: Colors.white,
),

今天dart更新到v1.23.0-4.0.pre版本后,我的代码发现了这个问题。

'textSelectionHandleColor' 已弃用,不应使用。请改用 TextSelectionThemeData.selectionHandleColor。此功能在 v1.23.0-4.0.pre 之后被弃用。 尝试将已弃用成员的使用替换为替换。

但我对如何使用 TextSelectionThemeData 感到困惑。

有人知道怎么做吗?谢谢!

【问题讨论】:

    标签: flutter dart themes deprecated


    【解决方案1】:

    您必须使用textSelectionTheme 属性并将其设置为TextSelectionThemeData

    import 'package:flutter/material.dart';
    
    
    void main() async {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
    
      @override
      Widget build(BuildContext context) {
    
        return MaterialApp(
            title: 'Flutter Demo App',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              accentColor: Color(0xffBA379B).withOpacity(.6),
              primaryColor: Color(0xffBA379B),
              textSelectionTheme: TextSelectionThemeData(
                selectionColor: Color(0xffBA379B).withOpacity(.5),
                cursorColor: Color(0xffBA379B).withOpacity(.6),
                selectionHandleColor: Color(0xffBA379B).withOpacity(1),
              ),
            ),
            home: Home(),
    
        );
      }
    
    }
    

    【讨论】:

      【解决方案2】:

      现在不推荐使用直接使用textSelectionHandleColor 的新Flutter 版本。但Flutter 添加了一种新的访问方式。

      MaterialApp(
        title: 'My App',
        theme: ThemeData(
          primaryColor: Colors.red,
          textSelectionTheme: TextSelectionThemeData(
            selectionColor: Color(0xff35a19d),
            cursorColor: Color(0xff35a19d),
            selectionHandleColor: Color(0xff35a19d),
          ),
        ),
        home: MyWidget(),
      );
      

      你可以像Theme.of(context).textSelectionTheme.selectionHandleColor这样访问

      【讨论】:

        猜你喜欢
        • 2021-04-30
        • 1970-01-01
        • 2022-07-01
        • 2020-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-18
        • 1970-01-01
        相关资源
        最近更新 更多