dart 是否可以在抖动中更改ShowDurationPicker颜色?

3b6akqbq  于 2022-12-15  发布在  其他
关注(0)|答案(1)|浏览(128)

尝试更改持续时间选择器的颜色主题,但软件包不允许我更改。在其他计时器选择器中,如showTimePickers,小部件包含一个构建器,您可以在其中添加主题,但在这个小部件中没有构建器。我目前正在使用这个软件包pub.dev link
我试着用一个主题来 Package 它,但没有用。

xqkwcwgp

xqkwcwgp1#

如果你像这样把你的主题数据放在MaterialApp中,你可以很容易地在showDurationPicker中改变颜色:

import 'package:flutter/material.dart';
import 'package:duration_picker/duration_picker.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Duration Picker Demo',
      theme: ThemeData(
        colorScheme: const ColorScheme.light(
          primary: Colors.red,
          secondary: Colors.green,
        ),
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Test')),
      body: Container(),
      floatingActionButton: Builder(
        builder: (BuildContext context) => FloatingActionButton(
          onPressed: () async {
            var resultingDuration = await showDurationPicker(
              context: context,
              initialTime: const Duration(minutes: 20),
            );

            if (!mounted) return;
            ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('Choose duration: $resultingDuration')));
          },
          tooltip: 'Popup Duration Picker',
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

输出:

相关问题