Created
March 28, 2022 17:07
-
-
Save mdebbar/79db43716109b12d571cc83941c2d621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:ui'; | |
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp(); | |
| @override | |
| Widget build(BuildContext context) { | |
| return const MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| body: _Duo( | |
| child: Text.rich( | |
| TextSpan( | |
| text: 'Lorem ', | |
| style: TextStyle( | |
| fontFamily: 'Roboto', | |
| fontSize: 16, | |
| // height: 2, | |
| // backgroundColor: Colors.red, | |
| ), | |
| children: [ | |
| TextSpan(text: 'ipsum मनुष्यों sit ', style: TextStyle(fontSize: 16)), | |
| TextSpan(text: 'amet', style: TextStyle(height: 2, fontSize: 16)), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class _Duo extends StatelessWidget { | |
| const _Duo({required this.child}); | |
| final Widget child; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Row( | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
| children: [ | |
| _Single(child, isDom: false), | |
| _Single(child, isDom: true), | |
| ], | |
| ); | |
| } | |
| } | |
| class _Single extends StatefulWidget { | |
| const _Single(this.child, {required this.isDom}); | |
| final Widget child; | |
| final bool isDom; | |
| @override | |
| State<_Single> createState() => _SingleState(); | |
| } | |
| class _SingleState extends State<_Single> { | |
| bool hovering = false; | |
| bool get shouldUseDom => widget.isDom || hovering; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container( | |
| padding: const EdgeInsets.all(8), | |
| child: MouseRegion( | |
| onEnter: (_) { | |
| setState(() { | |
| hovering = true; | |
| }); | |
| }, | |
| onExit: (_) { | |
| setState(() { | |
| hovering = false; | |
| }); | |
| }, | |
| child: DefaultTextStyle.merge( | |
| style: shouldUseDom | |
| ? const TextStyle(fontFeatures: [FontFeature.enable('aaaa')]) | |
| : const TextStyle(), | |
| child: widget.child, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment