123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import 'package:fis_i18n/i18n.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- class FConfigureLayoutStyle extends InheritedWidget implements FWidget {
- const FConfigureLayoutStyle({
- key,
- required this.child,
- required this.width,
- }) : super(child: child);
- final double width;
- final FWidget child;
- static double? of(BuildContext context) {
- final style =
- context.dependOnInheritedWidgetOfExactType<FConfigureLayoutStyle>();
- return style?.width;
- }
- @override
- bool updateShouldNotify(covariant InheritedWidget oldWidget) {
- return this.width != oldWidget.child;
- }
- }
- class FConfigureLayout extends FStatelessWidget {
- static const C_FONT_SIZE = 16.0;
- static const C_PADDING_LEFT = 25.0;
- static const C_PADDING_BOTTOM = 5.0;
- static const C_MARGIN_HORIZONTAL_SIZE = 15.0;
- static const C_MARGIN_VERTICAL_SIZE = 10.0;
-
- double C_FCONTAITNER_WIDTH = i18nBook.isCurrentChinese ? 80 : 160.0;
-
- final String title;
-
- final FWidget widget;
-
- final double? proportion;
-
- final bool? isRequired;
-
- final bool? isShowTitle;
- FConfigureLayout({
- required this.title,
- required this.widget,
- this.proportion = 1,
- this.isRequired = false,
- this.isShowTitle = true,
- });
- @override
- FWidget build(BuildContext context) {
- final width = FConfigureLayoutStyle.of(context);
- return FContainer(
- width: proportion! * width!,
- child: FRow(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- FSizedBox(
- width: 20,
- ),
- isShowTitle!
- ? _buildTitle()
- : FSizedBox(
- width: C_PADDING_LEFT,
- ),
- widget,
- ],
- ),
- );
- }
-
- FWidget _buildTitle() {
- final labelStyle = TextStyle(fontSize: C_FONT_SIZE);
- return FContainer(
- margin: EdgeInsets.symmetric(
- vertical: C_MARGIN_VERTICAL_SIZE,
- horizontal: C_MARGIN_HORIZONTAL_SIZE,
- ),
- width: C_FCONTAITNER_WIDTH,
- alignment: Alignment.centerLeft,
- child: FRow(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- FExpanded(
- child: FText.rich(
- TextSpan(
- children: [
- TextSpan(
- text: title,
- style: labelStyle,
- ),
- if (isRequired!) ...[
- TextSpan(
- text: ' *',
- style: labelStyle.copyWith(color: Colors.red),
- )
- ] else ...[
- TextSpan(text: '')
- ]
- ],
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
|