Skip to content

Conversation

TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Mar 10, 2022

part of #91605
fixes #101480

minimal code sample
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key, this.dark = false, this.useMaterial3 = true})
      : super(key: key);

  final bool dark;
  final bool useMaterial3;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Material App',
      themeMode: dark ? ThemeMode.dark : ThemeMode.light,
      theme: ThemeData.light().copyWith(
        useMaterial3: useMaterial3,
        colorScheme:
            useMaterial3 ? lightColorScheme : const ColorScheme.light(),
      ),
      darkTheme: ThemeData.dark().copyWith(
        useMaterial3: useMaterial3,
        colorScheme: useMaterial3 ? darkColorScheme : const ColorScheme.dark(),
      ),
      home: const TimePickerSample(),
    );
  }
}

class TimePickerSample extends StatelessWidget {
  const TimePickerSample({Key? key}) : super(key: key);

  Future<TimeOfDay?> _showTimePicker(BuildContext context) {
    return showTimePicker(
      initialTime: TimeOfDay.now(),
      initialEntryMode: TimePickerEntryMode.input,
      context: context,
      confirmText: 'Accept',
      cancelText: 'Reject',
      hourLabelText: 'Happy Hour',
      minuteLabelText: 'Happy Minute',
      helpText: 'Spend your time wisely',
      onEntryModeChanged: (TimePickerEntryMode mode) {
        print('Current Mode: $mode');
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('TimePicker Sample'),
      ),
      body: Center(
        child: OutlinedButton(
          onPressed: () => _showTimePicker(context),
          child: const Text('Show TimePicker'),
        ),
      ),
    );
  }
}

const seed = Color(0xFF6750A4);

const lightColorScheme = ColorScheme(
  brightness: Brightness.light,
  primary: Color(0xFF6750A4),
  onPrimary: Color(0xFFFFFFFF),
  primaryContainer: Color(0xFFEADDFF),
  onPrimaryContainer: Color(0xFF21005D),
  secondary: Color(0xFF625B71),
  onSecondary: Color(0xFFFFFFFF),
  secondaryContainer: Color(0xFFE8DEF8),
  onSecondaryContainer: Color(0xFF1D192B),
  tertiary: Color(0xFF7D5260),
  onTertiary: Color(0xFFFFFFFF),
  tertiaryContainer: Color(0xFFFFD8E4),
  onTertiaryContainer: Color(0xFF31111D),
  error: Color(0xFFB3261E),
  errorContainer: Color(0xFFF9DEDC),
  onError: Color(0xFFFFFFFF),
  onErrorContainer: Color(0xFF410E0B),
  background: Color(0xFFFFFBFE),
  onBackground: Color(0xFF1C1B1F),
  surface: Color(0xFFFFFBFE),
  onSurface: Color(0xFF1C1B1F),
  surfaceVariant: Color(0xFFE7E0EC),
  onSurfaceVariant: Color(0xFF49454F),
  outline: Color(0xFF79747E),
  onInverseSurface: Color(0xFFF4EFF4),
  inverseSurface: Color(0xFF313033),
  inversePrimary: Color(0xFFD0BCFF),
  shadow: Color(0xFF000000),
);

const darkColorScheme = ColorScheme(
  brightness: Brightness.dark,
  primary: Color(0xFFD0BCFF),
  onPrimary: Color(0xFF381E72),
  primaryContainer: Color(0xFF4F378B),
  onPrimaryContainer: Color(0xFFEADDFF),
  secondary: Color(0xFFCCC2DC),
  onSecondary: Color(0xFF332D41),
  secondaryContainer: Color(0xFF4A4458),
  onSecondaryContainer: Color(0xFFE8DEF8),
  tertiary: Color(0xFFEFB8C8),
  onTertiary: Color(0xFF492532),
  tertiaryContainer: Color(0xFF633B48),
  onTertiaryContainer: Color(0xFFFFD8E4),
  error: Color(0xFFF2B8B5),
  errorContainer: Color(0xFF8C1D18),
  onError: Color(0xFF601410),
  onErrorContainer: Color(0xFFF9DEDC),
  background: Color(0xFF1C1B1F),
  onBackground: Color(0xFFE6E1E5),
  surface: Color(0xFF1C1B1F),
  onSurface: Color(0xFFE6E1E5),
  surfaceVariant: Color(0xFF49454F),
  onSurfaceVariant: Color(0xFFCAC4D0),
  outline: Color(0xFF938F99),
  onInverseSurface: Color(0xFF1C1B1F),
  inverseSurface: Color(0xFFE6E1E5),
  inversePrimary: Color(0xFF6750A4),
  shadow: Color(0xFF000000),
);
M2 M3
M2 M3

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 10, 2022
@TahaTesser TahaTesser changed the title Migrate TimerPicker to Material 3 Migrate TimePicker to Material 3 Mar 10, 2022
@cedvdb
Copy link
Contributor

cedvdb commented Mar 10, 2022

The red looks really out of place imo. I know you have specs but it's not clear which of PM or AM is selected there.

@TahaTesser
Copy link
Member Author

The red looks really out of place imo. I know you have specs but it's not clear which of PM or AM is selected there.

I agree but as you said, this is just following Material 3 Specs

@felix-ht
Copy link

@cedvdb It looks off in the official example as well. I certainly can't tell is it's supposed to be am or pm.

I would even go as far as saying that the whole am pm section looks very out of place in general. None of the other examples on https://m3.material.io use color in a similar way to indicate a selected state.

@cedvdb
Copy link
Contributor

cedvdb commented Mar 11, 2022

In your example I think it's more obvious that AM is selected, but with @TahaTesser example I'd have say it's PM even though I know with the context it's AM (because he posted m2 picture). The color used is very weird too but I assume it's just accent.

Let's hope that color is overridable or that there is some communications between the flutter and m3 team

@felix-ht
Copy link

@cedvdb now that you metion it: In the example by @TahaTesser the white part is supposed to indicate the selection.

In the example from M3 I was assuming that black would have to indicate the selection, if it were to follow the same schema as the example here.
On second thought tho, it's much more likely that in the M3 example the colored field is the selection.
If that's the case it might be wrong here? So also on a light theme the color would indicate the selection?

@oodavid
Copy link

oodavid commented Apr 26, 2022

Reading through the Material3 specs, looks to me like the hour-hand has the right approach:

Screenshot 2022-04-26 at 14 56 07

I think the colors here look right for the AM/PM input; 7 is selected, 6 is not, no border, correct BG color...

@TahaTesser
Copy link
Member Author

TahaTesser commented Apr 26, 2022

We're waiting for official Material 3 specs for the Time picker and date picker so this migration can use Material 3 tokens.

In current the state of the PR, I've simply copied color scheme from native implementation. This is not using tokens in Flutter right now. This will change after M3 specs are released or when tokens are available.

@guidezpl
Copy link
Member

guidezpl commented Jun 3, 2022

md.comp.time-picker should be available, no? cc @darrenaustin

@TahaTesser TahaTesser marked this pull request as draft June 14, 2022 14:48
@TahaTesser
Copy link
Member Author

I will file a new PR when specs and tokens are ready to use, see #105899 (comment)

@TahaTesser TahaTesser closed this Jul 25, 2022
@TahaTesser TahaTesser deleted the m3_time_picker branch July 25, 2022 11:00
@TahaTesser
Copy link
Member Author

specs are available https://m3.material.io/components/time-pickers/overview, I will re-purpose this PR and migrate TimePicker to M3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update TimePicker to support Material 3
5 participants