最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - How to break up a class to keep the size of the code to a reasonable length - Stack Overflow

programmeradmin4浏览0评论

Amendment to original question. Can I pass something in to the SessionEntryInfo class that would allow me to add some buttons to the original screen from page4?

I have a class page as seen below. After the user makes a selection in the dropdownmenu, I'd like to display some other buttons on the same screen. In order to keep the class short, I was trying to put the other buttons to be displayed in another class, but I'm not sure this is allowed. From what I understand I should only have 1 layout per page. Can someone suggest a way to do this please? Thanks

  const Page2({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
            textTheme: TextTheme(
                displayLarge: const TextStyle(
                    fontSize: 84, fontWeight: FontWeight.bold))),
        home: Scaffold(
            body: Center(
                child: Column(children: <Widget>[
                SizedBox(height: 50),
                DropdownMenu(
                width: 200,
                textStyle: TextStyle(fontSize: 14),
                label: const Text('Session Options'),
                inputDecorationTheme: InputDecorationTheme(
                  isDense: true,
                  contentPadding: const EdgeInsets.symmetric(horizontal: 5),
                  constraints: BoxConstraints.tight(const Size.fromHeight(40)),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                  )),
              onSelected: (value) {
                debugPrint(value);
                if (value == 'Create Session') {
                   debugPrint("Calling SessionEntryInfo");
                   SessionEntryInfo();
                 }

              },
              dropdownMenuEntries: <DropdownMenuEntry<String>>[
                DropdownMenuEntry(
                    value: 'Create Session', label: 'Create Session'),
                DropdownMenuEntry(value: 'Edit Session', label: 'Edit Session'),
                DropdownMenuEntry(
                    value: 'Delete Session', label: 'Delete Session'),
              ]),
              ]))
            )
        );
  }
}```

Amendment to original question. Can I pass something in to the SessionEntryInfo class that would allow me to add some buttons to the original screen from page4?

I have a class page as seen below. After the user makes a selection in the dropdownmenu, I'd like to display some other buttons on the same screen. In order to keep the class short, I was trying to put the other buttons to be displayed in another class, but I'm not sure this is allowed. From what I understand I should only have 1 layout per page. Can someone suggest a way to do this please? Thanks

  const Page2({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
            textTheme: TextTheme(
                displayLarge: const TextStyle(
                    fontSize: 84, fontWeight: FontWeight.bold))),
        home: Scaffold(
            body: Center(
                child: Column(children: <Widget>[
                SizedBox(height: 50),
                DropdownMenu(
                width: 200,
                textStyle: TextStyle(fontSize: 14),
                label: const Text('Session Options'),
                inputDecorationTheme: InputDecorationTheme(
                  isDense: true,
                  contentPadding: const EdgeInsets.symmetric(horizontal: 5),
                  constraints: BoxConstraints.tight(const Size.fromHeight(40)),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                  )),
              onSelected: (value) {
                debugPrint(value);
                if (value == 'Create Session') {
                   debugPrint("Calling SessionEntryInfo");
                   SessionEntryInfo();
                 }

              },
              dropdownMenuEntries: <DropdownMenuEntry<String>>[
                DropdownMenuEntry(
                    value: 'Create Session', label: 'Create Session'),
                DropdownMenuEntry(value: 'Edit Session', label: 'Edit Session'),
                DropdownMenuEntry(
                    value: 'Delete Session', label: 'Delete Session'),
              ]),
              ]))
            )
        );
  }
}```
Share Improve this question edited Jan 19 at 3:04 Chris asked Jan 18 at 23:45 ChrisChris 53 bronze badges 1
  • I don't see a long class as a bad sign. Methods that span more than one page, on the other hand, deserve rewrites. Same goes for anything needing more than ten indents. – Randal Schwartz Commented Jan 19 at 0:54
Add a comment  | 

1 Answer 1

Reset to default 0

It's quite common to create custom widgets in your Flutter application for common UI patterns.

For example, you could create a custom widget subclassing DropdownMenu with all the logic you have here.

发布评论

评论列表(0)

  1. 暂无评论