简体   繁体   English

当我在颤动中按下 ElevatedButton 时,我希望能够更改 Fontfamily

[英]I would like to be able to change the Fontfamily when I press the ElevatedButton in flutter

I want the Textfield and the fontFamily in the picture at the top to change when the ElevatedButton is pressed.我希望在按下 ElevatedButton 时更改顶部图片中的 Textfield 和 fontFamily。 What should I do?我应该怎么办? I want to try GetX.我想尝试 GetX。

在此处输入图片说明

home_page.dart主页.dart

ListView(
  scrollDirection: Axis.horizontal,
 children: [
      FontFamilyWidget(
             fontFamily: 'Cafe24SsurroundAir',
             buttonName: '✈️ 카페24 써라운드 에어'),
             const SizedBox(width: 5),
      FontFamilyWidget(
             fontFamily: 'RIDIBatang', buttonName: '📚 리디바탕'),
             const SizedBox(width: 5),
      FontFamilyWidget(
             fontFamily: 'InkLipquid', buttonName: ' 잉크립퀴드체'),
             const SizedBox(width: 5),
              .
              .
              .

fontfamily_widget.dart fontfamily_widget.dart

在此处输入图片说明

part of 'font_controller.dart' “font_controller.dart”的一部分

 String select = 'RIDIBatang';

  void onClickChangeFont(String changedFontFamily) {
    select = changedFontFamily;
    update();
  }

part of 'fontfamily_widget.dart' “fontfamily_widget.dart”的一部分

class FontFamilyWidget extends StatefulWidget {
  final String fontFamily;
  final String buttonName;
  final String changedFontFamily;

  const FontFamilyWidget({
    Key? key,
    required this.fontFamily,
    required this.buttonName,
    required this.changedFontFamily,
  }) : super(key: key);

  @override
  _FontFamilyWidgetState createState() => _FontFamilyWidgetState();
}

class _FontFamilyWidgetState extends State<FontFamilyWidget> {
  FontController c = Get.find();

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      //텍스트필드와 상단 텍스트의 fontfamily를 변경해주는 함수
      onPressed: () {
        c.onClickChangeFont(widget.changedFontFamily);
      },

      child: Text(
        widget.buttonName,
        style: TextStyle(fontFamily: widget.fontFamily),
      ),
    );
  }
}


After that, FontFamilyWidget was applied to home_page.dart.之后,FontFamilyWidget 被应用到 home_page.dart。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM