Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Make some text selectable and add mouse cursors to clickable things #539

Merged
merged 6 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 197 additions & 131 deletions lib/codeviewer/code_segments.dart

Large diffs are not rendered by default.

204 changes: 108 additions & 96 deletions lib/demos/cupertino/cupertino_picker_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,122 +44,134 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
}

Widget _buildDatePicker(BuildContext context) {
return GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoDatePicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.date,
initialDateTime: date,
onDateTimeChanged: (newDateTime) {
setState(() => date = newDateTime);
},
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoDatePicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.date,
initialDateTime: date,
onDateTimeChanged: (newDateTime) {
setState(() => date = newDateTime);
},
),
),
);
},
child: _Menu(children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerDate),
Text(
DateFormat.yMMMMd().format(date),
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
);
},
child: _Menu(children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerDate),
Text(
DateFormat.yMMMMd().format(date),
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
]),
]),
),
);
}

Widget _buildTimePicker(BuildContext context) {
return GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoDatePicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.time,
initialDateTime: time,
onDateTimeChanged: (newDateTime) {
setState(() => time = newDateTime);
},
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoDatePicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.time,
initialDateTime: time,
onDateTimeChanged: (newDateTime) {
setState(() => time = newDateTime);
},
),
),
),
);
},
child: _Menu(
children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerTime),
Text(
DateFormat.jm().format(time),
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
],
);
},
child: _Menu(
children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerTime),
Text(
DateFormat.jm().format(time),
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
],
),
),
);
}

Widget _buildDateAndTimePicker(BuildContext context) {
return GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoDatePicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.dateAndTime,
initialDateTime: dateTime,
onDateTimeChanged: (newDateTime) {
setState(() => dateTime = newDateTime);
},
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoDatePicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.dateAndTime,
initialDateTime: dateTime,
onDateTimeChanged: (newDateTime) {
setState(() => dateTime = newDateTime);
},
),
),
),
);
},
child: _Menu(
children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerDateTime),
Flexible(
child: Text(
DateFormat.yMMMd().add_jm().format(dateTime),
style: const TextStyle(color: CupertinoColors.inactiveGray),
);
},
child: _Menu(
children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerDateTime),
Flexible(
child: Text(
DateFormat.yMMMd().add_jm().format(dateTime),
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
),
),
],
],
),
),
);
}

Widget _buildCountdownTimerPicker(BuildContext context) {
return GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoTimerPicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
initialTimerDuration: timer,
onTimerDurationChanged: (newTimer) {
setState(() => timer = newTimer);
},
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
_showDemoPicker(
context: context,
child: _BottomPicker(
child: CupertinoTimerPicker(
backgroundColor:
CupertinoColors.systemBackground.resolveFrom(context),
initialTimerDuration: timer,
onTimerDurationChanged: (newTimer) {
setState(() => timer = newTimer);
},
),
),
),
);
},
child: _Menu(
children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerTimer),
Text(
'${timer.inHours}:'
'${(timer.inMinutes % 60).toString().padLeft(2, '0')}:'
'${(timer.inSeconds % 60).toString().padLeft(2, '0')}',
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
],
);
},
child: _Menu(
children: [
Text(GalleryLocalizations.of(context).demoCupertinoPickerTimer),
Text(
'${timer.inHours}:'
'${(timer.inMinutes % 60).toString().padLeft(2, '0')}:'
'${(timer.inSeconds % 60).toString().padLeft(2, '0')}',
style: const TextStyle(color: CupertinoColors.inactiveGray),
),
],
),
),
);
}
Expand Down
9 changes: 4 additions & 5 deletions lib/demos/material/text_field_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -95,14 +94,14 @@ class _PasswordFieldState extends State<PasswordField> with RestorationMixin {
hintText: widget.hintText,
labelText: widget.labelText,
helperText: widget.helperText,
suffixIcon: GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onTap: () {
suffixIcon: IconButton(
onPressed: () {
setState(() {
_obscureText.value = !_obscureText.value;
});
},
child: Icon(
hoverColor: Colors.transparent,
icon: Icon(
_obscureText.value ? Icons.visibility : Icons.visibility_off,
semanticLabel: _obscureText.value
? GalleryLocalizations.of(context)
Expand Down
39 changes: 21 additions & 18 deletions lib/demos/reference/transformations_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,27 @@ class _TransformationsDemoState extends State<TransformationsDemo>
}

return ClipRect(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTapUp: _onTapUp,
child: InteractiveViewer(
key: _targetKey,
scaleEnabled: !kIsWeb,
transformationController: _transformationController,
boundaryMargin: EdgeInsets.symmetric(
horizontal: viewportSize.width,
vertical: viewportSize.height,
),
minScale: 0.01,
onInteractionStart: _onScaleStart,
child: SizedBox.expand(
child: CustomPaint(
size: _board.size,
painter: _BoardPainter(
board: _board,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTapUp: _onTapUp,
child: InteractiveViewer(
key: _targetKey,
scaleEnabled: !kIsWeb,
transformationController: _transformationController,
boundaryMargin: EdgeInsets.symmetric(
horizontal: viewportSize.width,
vertical: viewportSize.height,
),
minScale: 0.01,
onInteractionStart: _onScaleStart,
child: SizedBox.expand(
child: CustomPaint(
size: _board.size,
painter: _BoardPainter(
board: _board,
),
),
),
),
Expand Down
17 changes: 10 additions & 7 deletions lib/feature_discovery/feature_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,16 @@ class _FeatureDiscoveryState extends State<FeatureDiscovery>
type: MaterialType.transparency,
child: Stack(
children: [
GestureDetector(
key: FeatureDiscovery.gestureDetectorKey,
onTap: dismiss,
child: Container(
width: double.infinity,
height: double.infinity,
color: Colors.transparent,
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
key: FeatureDiscovery.gestureDetectorKey,
onTap: dismiss,
child: Container(
width: double.infinity,
height: double.infinity,
color: Colors.transparent,
),
),
),
Background(
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class _AboutDialog extends StatelessWidget {
children: [
FutureBuilder(
future: getVersionNumber(),
builder: (context, snapshot) => Text(
builder: (context, snapshot) => SelectableText(
snapshot.hasData ? '$name ${snapshot.data}' : name,
style: textTheme.headline4.apply(color: colorScheme.onPrimary),
),
),
const SizedBox(height: 24),
RichText(
text: TextSpan(
SelectableText.rich(
TextSpan(
children: [
TextSpan(
style: bodyTextStyle,
Expand Down Expand Up @@ -91,7 +91,7 @@ class _AboutDialog extends StatelessWidget {
),
),
const SizedBox(height: 18),
Text(
SelectableText(
legalese,
style: bodyTextStyle,
),
Expand Down
Loading