import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: RichTextDemoPage2(),
),
),
);
}
}
class RichTextDemoPage2 extends StatefulWidget {
@override
_RichTextDemoState2 createState() => _RichTextDemoState2();
}
class _RichTextDemoState2 extends State<RichTextDemoPage2> {
double size = 50;
@override
Widget build(BuildContext mainContext) {
return Scaffold(
appBar: AppBar(
title: const Text("RichTextDemoPage"),
actions: <Widget>[
IconButton(
onPressed: () {
setState(() {
size += 10;
});
},
icon: const Icon(Icons.add_circle_outline),
),
IconButton(
onPressed: () {
setState(() {
size -= 10;
});
},
icon: const Icon(Icons.remove_circle_outline),
)
],
),
body: SelectionArea(
child: Container(
margin: const EdgeInsets.all(10),
child: Center(
child: Text.rich(
TextSpan(
children: <InlineSpan>[
const TextSpan(text: 'Flutter is'),
const WidgetSpan(
baseline: TextBaseline.alphabetic,
/// change alignment to next case
/// alignment: PlaceholderAlignment.bottom,
alignment: PlaceholderAlignment.middle,
child: SizedBox(
width: 120,
height: 50,
child: Card(
color: Colors.yellowAccent,
child: Center(child: Text('Hello World!'))),
)),
WidgetSpan(
child: SizedBox(
width: size > 0 ? size : 0,
height: size > 0 ? size : 0,
child: Image.network(
"https://avatars.githubusercontent.com/u/10770362?s=40&v=4",
fit: BoxFit.cover,
),
)),
const TextSpan(text: 'the best!'),
const WidgetSpan(
child: SelectionContainer.disabled(
child: Text(' not copy'),
),
),
],
),
),
),
),
),
);
}
}
SelectionAreadidn’t match the expected behavior withWidgetSpan, this issue can be reproduce in the master and stable.Steps to Reproduce
Code sample, the case isSelectionAreawithWidgetSpanExpected results:
SelectAll, start and end handle show in the right way.Actual results:
Select not in order when drag handle like gif below:
When click
SelectAll, start and end handle not show in the right way, like image below:I found that when
_additionssort bycompareOrderfunction,TextinWidgetSpanis difficult to calculate the vertical height consistency in_compareVertically.ais normal Text andbisWidgetSpanText .So
WidgetSpanalway the first or last inselectablesList.Code sample
Logs