Skip to content

Commit

Permalink
Improve header buttons, make them platform-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanderwozniak committed Mar 22, 2022
1 parent 782edad commit a14a259
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/src/customization/header_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HeaderStyle {
final TextStyle formatButtonTextStyle;

/// Background `Decoration` for FormatButton.
final Decoration formatButtonDecoration;
final BoxDecoration formatButtonDecoration;

/// Internal padding of the whole header.
final EdgeInsets headerPadding;
Expand Down Expand Up @@ -77,7 +77,7 @@ class HeaderStyle {
final bool rightChevronVisible;

/// Decoration of the header.
final Decoration decoration;
final BoxDecoration decoration;

/// Creates a `HeaderStyle` used by `TableCalendar` widget.
const HeaderStyle({
Expand All @@ -86,7 +86,7 @@ class HeaderStyle {
this.formatButtonShowsNext = true,
this.titleTextFormatter,
this.titleTextStyle = const TextStyle(fontSize: 17.0),
this.formatButtonTextStyle = const TextStyle(),
this.formatButtonTextStyle = const TextStyle(fontSize: 14.0),
this.formatButtonDecoration = const BoxDecoration(
border: const Border.fromBorderSide(BorderSide()),
borderRadius: const BorderRadius.all(Radius.circular(12.0)),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/widgets/custom_icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class CustomIconButton extends StatelessWidget {
Expand All @@ -24,7 +25,7 @@ class CustomIconButton extends StatelessWidget {
Widget build(BuildContext context) {
return Padding(
padding: margin,
child: Platform.isIOS || Platform.isMacOS
child: !kIsWeb && (Platform.isIOS || Platform.isMacOS)
? CupertinoButton(
onPressed: onTap,
padding: padding,
Expand Down
34 changes: 24 additions & 10 deletions lib/src/widgets/format_button.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2019 Aleksander Woźniak
// SPDX-License-Identifier: Apache-2.0

import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import '../shared/utils.dart' show CalendarFormat;
Expand All @@ -9,7 +13,7 @@ class FormatButton extends StatelessWidget {
final CalendarFormat calendarFormat;
final ValueChanged<CalendarFormat> onTap;
final TextStyle textStyle;
final Decoration decoration;
final BoxDecoration decoration;
final EdgeInsets padding;
final bool showsNextFormat;
final Map<CalendarFormat, String> availableCalendarFormats;
Expand All @@ -27,17 +31,27 @@ class FormatButton extends StatelessWidget {

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => onTap(_nextFormat()),
child: Container(
decoration: decoration,
padding: padding,
child: Text(
_formatButtonText,
style: textStyle,
),
final child = Container(
decoration: decoration,
padding: padding,
child: Text(
_formatButtonText,
style: textStyle,
),
);

return !kIsWeb && (Platform.isIOS || Platform.isMacOS)
? CupertinoButton(
onPressed: () => onTap(_nextFormat()),
padding: EdgeInsets.zero,
child: child,
)
: InkWell(
borderRadius:
decoration.borderRadius?.resolve(Directionality.of(context)),
onTap: () => onTap(_nextFormat()),
child: child,
);
}

String get _formatButtonText => showsNextFormat
Expand Down

0 comments on commit a14a259

Please sign in to comment.