@@ -551,4 +551,111 @@ void main() {
551551
552552 expect (eventLog, isEmpty);
553553 }, skip: kIsWeb || ! isMainChannel); // https://github.com/flutter/flutter/pull/129851
554+
555+ testWidgets ('fontWeight decoder' , (WidgetTester tester) async {
556+ final runtime = Runtime ()
557+ ..update (const LibraryName (< String > ['core' ]), createCoreWidgets ())
558+ ..update (const LibraryName (< String > ['test' ]), parseLibraryFile ('import core; widget root = SizedBox();' ));
559+ addTearDown (runtime.dispose);
560+ await tester.pumpWidget (
561+ RemoteWidget (
562+ runtime: runtime,
563+ data: DynamicContent (),
564+ widget: const FullyQualifiedWidgetName (LibraryName (< String > ['test' ]), 'root' ),
565+ onEvent: (String name, DynamicMap arguments) { },
566+ ),
567+ );
568+
569+ // String values w100–w900 in textStyle.
570+ for (final (String name, FontWeight weight) in < (String , FontWeight )> [
571+ ('w100' , FontWeight .w100), ('w200' , FontWeight .w200), ('w300' , FontWeight .w300),
572+ ('w400' , FontWeight .w400), ('w500' , FontWeight .w500), ('w600' , FontWeight .w600),
573+ ('w700' , FontWeight .w700), ('w800' , FontWeight .w800), ('w900' , FontWeight .w900),
574+ ('normal' , FontWeight .w400), ('bold' , FontWeight .w700),
575+ ]) {
576+ runtime.update (const LibraryName (< String > ['test' ]), parseLibraryFile ('''
577+ import core;
578+ widget root = Directionality(
579+ textDirection: "ltr",
580+ child: Text(text: "hello", style: { fontWeight: "$name ", fontSize: 16.0 }),
581+ );
582+ ''' ));
583+ await tester.pump ();
584+ expect (tester.widget <Text >(find.byType (Text )).style? .fontWeight, weight, reason: 'string "$name "' );
585+ }
586+
587+ // Integer values 100–900 in textStyle.
588+ for (final (int value, FontWeight weight) in < (int , FontWeight )> [
589+ (100 , FontWeight .w100), (200 , FontWeight .w200), (300 , FontWeight .w300),
590+ (400 , FontWeight .w400), (500 , FontWeight .w500), (600 , FontWeight .w600),
591+ (700 , FontWeight .w700), (800 , FontWeight .w800), (900 , FontWeight .w900),
592+ ]) {
593+ runtime.update (const LibraryName (< String > ['test' ]), parseLibraryFile ('''
594+ import core;
595+ widget root = Directionality(
596+ textDirection: "ltr",
597+ child: Text(text: "hello", style: { fontWeight: $value , fontSize: 16.0 }),
598+ );
599+ ''' ));
600+ await tester.pump ();
601+ expect (tester.widget <Text >(find.byType (Text )).style? .fontWeight, weight, reason: 'int $value ' );
602+ }
603+
604+ // Unknown string returns null.
605+ runtime.update (const LibraryName (< String > ['test' ]), parseLibraryFile ('''
606+ import core;
607+ widget root = Directionality(
608+ textDirection: "ltr",
609+ child: Text(text: "hello", style: { fontWeight: "heavy", fontSize: 16.0 }),
610+ );
611+ ''' ));
612+ await tester.pump ();
613+ expect (tester.widget <Text >(find.byType (Text )).style? .fontWeight, isNull);
614+
615+ // Missing key returns null.
616+ runtime.update (const LibraryName (< String > ['test' ]), parseLibraryFile ('''
617+ import core;
618+ widget root = Directionality(
619+ textDirection: "ltr",
620+ child: Text(text: "hello", style: { fontSize: 16.0 }),
621+ );
622+ ''' ));
623+ await tester.pump ();
624+ expect (tester.widget <Text >(find.byType (Text )).style? .fontWeight, isNull);
625+
626+ // String values w100–w900 in strutStyle.
627+ for (final (String name, FontWeight weight) in < (String , FontWeight )> [
628+ ('w100' , FontWeight .w100), ('w200' , FontWeight .w200), ('w300' , FontWeight .w300),
629+ ('w400' , FontWeight .w400), ('w500' , FontWeight .w500), ('w600' , FontWeight .w600),
630+ ('w700' , FontWeight .w700), ('w800' , FontWeight .w800), ('w900' , FontWeight .w900),
631+ ('normal' , FontWeight .w400), ('bold' , FontWeight .w700),
632+ ]) {
633+ runtime.update (const LibraryName (< String > ['test' ]), parseLibraryFile ('''
634+ import core;
635+ widget root = Directionality(
636+ textDirection: "ltr",
637+ child: Text(text: "hello", strutStyle: { fontWeight: "$name ", fontSize: 16.0 }),
638+ );
639+ ''' ));
640+ await tester.pump ();
641+ expect (tester.widget <Text >(find.byType (Text )).strutStyle? .fontWeight, weight, reason: 'strutStyle string "$name "' );
642+ }
643+
644+ // Integer values 100–900 in strutStyle.
645+ for (final (int value, FontWeight weight) in < (int , FontWeight )> [
646+ (100 , FontWeight .w100), (200 , FontWeight .w200), (300 , FontWeight .w300),
647+ (400 , FontWeight .w400), (500 , FontWeight .w500), (600 , FontWeight .w600),
648+ (700 , FontWeight .w700), (800 , FontWeight .w800), (900 , FontWeight .w900),
649+ ]) {
650+ runtime.update (const LibraryName (< String > ['test' ]), parseLibraryFile ('''
651+ import core;
652+ widget root = Directionality(
653+ textDirection: "ltr",
654+ child: Text(text: "hello", strutStyle: { fontWeight: $value , fontSize: 16.0 }),
655+ );
656+ ''' ));
657+ await tester.pump ();
658+ expect (tester.widget <Text >(find.byType (Text )).strutStyle? .fontWeight, weight, reason: 'strutStyle int $value ' );
659+ }
660+ });
554661}
0 commit comments