如何在Flutter中更改复选框的边框颜色?默认情况下,它显示为黑色,但我希望显示为灰色

时间:2020-01-08 17:55:41

标签: flutter dart

如何在Flutter中更改复选框的边框颜色?默认情况下,它显示为黑色,但我希望使用灰色。

3 个答案:

答案 0 :(得分:4)

CheckBox的边框颜色来自您的unselectedWidgetColor中的ThemeData

将以下ThemeData添加到您的MaterialApp

MaterialApp(
  title: 'Flutter Demo',
  debugShowCheckedModeBanner: false,
  theme: ThemeData(
    primarySwatch: Colors.blue,
    unselectedWidgetColor: Colors.red, // <-- your color
  ),
  home: MyHomePage(title: 'Flutter Demo Home Page'),
);

如果您不想为MaterialApp的{​​{1}}添加颜色,则可以用ThemeData小部件包装CheckBox小部件,以下是用于您的参考:

Theme

我希望这会有所帮助,如有任何疑问,请发表评论。 如果此答案对您有帮助,请接受并投票给该答案。

答案 1 :(得分:3)

您可以使用[ Class { __setters__: [ '$attributes', '$persisted', 'primaryKeyValue', '$originalAttributes', '$relations', '$sideLoaded', '$parent', '$frozen', '$visible', '$hidden' ], '$attributes': { id: 2, code: 'ING-NOT-2019', description: 'Inglês Noturno 2019', start_date: 2019-12-30T03:00:00.000Z, end_date: 2019-12-31T03:00:00.000Z, period: 'Noturno', language: 'Inglês', status: false, user_id: 1, created_at: 2019-12-30T13:04:47.000Z, updated_at: 2020-01-05T19:08:00.000Z, language_substring: 'US', quiz: [Array] }, '$persisted': true, '$originalAttributes': { id: 2, code: 'ING-NOT-2019', description: 'Inglês Noturno 2019', start_date: 2019-12-30T03:00:00.000Z, end_date: 2019-12-31T03:00:00.000Z, period: 'Noturno', language: 'Inglês', status: false, user_id: 1, created_at: 2019-12-30T13:04:47.000Z, updated_at: 2020-01-05T19:08:00.000Z, language_substring: 'US' }, '$relations': {}, '$sideLoaded': {}, '$parent': null, '$frozen': false, '$visible': undefined, '$hidden': undefined } ] 更改未选择的小部件颜色,如下所示

Theme

答案 2 :(得分:0)

Checkbox(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(3),
      ),
      materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
      value: true,
      onChanged: (newValue) {},

      /// Set your color here
      fillColor: MaterialStateProperty.all(Colors.grey),
    )