tx_design 0.2.9 copy "tx_design: ^0.2.9" to clipboard
tx_design: ^0.2.9 copied to clipboard

A custom component library that contains some basic UI components and provides theme configuration.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:tx_design/form/form_item_theme.dart';
import 'package:tx_design/localizations.dart';
import 'package:tx_design/tx_design.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ThemeMode _themeMode = ThemeMode.light;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorSchemeSeed: Colors.purple,
        brightness: Brightness.light,
        extensions: const [
          SpacingThemeData(),
          RadiusThemeData(),
          TxCellThemeData(),
          FormItemThemeData(
            inputDecorationTheme: InputDecorationTheme(
              border: InputBorder.none,
              focusedBorder: InputBorder.none,
              enabledBorder: InputBorder.none,
              errorBorder: InputBorder.none,
              disabledBorder: InputBorder.none,
              focusedErrorBorder: InputBorder.none,
            ),
          )
        ],
        useMaterial3: true,
      ),
      themeMode: _themeMode,
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.purple,
        brightness: Brightness.dark,
        extensions: const [
          SpacingThemeData(),
          RadiusThemeData(),
          TxCellThemeData(),
        ],
        useMaterial3: true,
      ),
      locale: const Locale('zh', 'CN'),
      supportedLocales: const [Locale('en', 'US'), Locale('zh', 'CN')],
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        TxLocalizations.delegate,
      ],
      home: MyHomePage(
          title: 'HomePage',
          changeTheme: () {
            setState(() {
              if (_themeMode == ThemeMode.dark) {
                _themeMode = ThemeMode.light;
              } else {
                _themeMode = ThemeMode.dark;
              }
            });
          }),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title, required this.changeTheme});

  final String title;

  final VoidCallback changeTheme;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Tx Design')),
      body: FormView(),
    );
  }
}

class FormView extends StatelessWidget {
  FormView({super.key});

  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  final Map form = {};

  static const List<String> sources = ['选项1', '选项2', '选项3'];

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: SingleChildScrollView(
            padding: const EdgeInsets.all(12.0),
            child: Form(
              key: _formKey,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  InputFormField(
                    labelText: '输入框',
                    // required: true,
                    onChanged: (val) => form['field1'] = val,
                    initialValue: form['field1'],
                    // direction: Axis.horizontal,
                  ),
                  NumberFormField(
                    labelText: '数字输入框',
                    required: true,
                    minimumValue: -10,
                    maximumValue: 20,
                    onChanged: (val) => form['field2'] = val,
                    initialValue: form['field2'],
                    // direction: Axis.horizontal,
                  ),
                  // const SizedBox(height: 8.0),
                  CheckboxFormField(
                    sources: sources,
                    labelMapper: (data) => data,
                    labelText: 'CheckBox多选',
                    minPickNumber: 1,
                    onChanged: (val) =>
                        form['field3'] = val?.map((e) => e).toSet(),
                    initialValue: form['field3'],
                    required: true,
                  ),
                  // const SizedBox(height: 8.0),
                  DatePickerFormField(
                    labelText: '日期选择',
                    onChanged: (val) => form['field4'] = val?.format(),
                    initialDateStr: form['field4'],
                  ),
                  DatetimePickerFormField(
                    labelText: '日期时间选择',
                    onChanged: (val) => form['field5'] = val,
                    initialDatetime: form['field5'],
                    required: true,
                    firstDate: DateTime.now(),
                  ),
                  TimePickerFormField(
                    labelText: '时间选择',
                    onChanged: (val) => form['field9'] = val,
                    initialTime: form['field9'],
                    required: true,
                  ),
                  // const SizedBox(height: 8.0),
                  DateRangePickerFormField(
                    labelText: '时间区间选择',
                    onChanged: (val) => form['field6'] = val,
                    initialValue: form['field6'],
                    required: true,
                    firstDate: DateTime.now(),
                  ),
                  DatetimeRangePickerFormField(
                    labelText: '时间区间选择',
                    onChanged: (val) => form['field6'] = val,
                    initialValue: form['field6'],
                    required: true,
                    firstDate: DateTime.now(),
                  ),
                  DropdownFormField(
                    sources: sources,
                    labelMapper: (data) => data,
                    labelText: '下拉选择',
                    onChanged: (val) => form['field7'] = val,
                    initialValue: form['field7'],
                    required: true,
                    direction: Axis.horizontal,
                    isDense: true,
                    isExpanded: true,
                  ),
                  PickerFormField(
                    sources: sources,
                    labelMapper: (data) => data,
                    labelText: '单项选择',
                    onChanged: (val) => form['field7'] = val,
                    initialValue: form['field7'],
                    required: true,
                  ),
                  RadioFormField(
                    sources: sources,
                    labelMapper: (data) => data,
                    labelText: 'Radio单选',
                    onChanged: (val) => form['field7'] = val,
                    initialValue: form['field7'],
                    required: true,
                    direction: Axis.horizontal,
                  ),
                  MultiPickerFormField(
                    sources: sources,
                    labelMapper: (data) => data,
                    labelText: '多选',
                    minPickNumber: 1,
                    onChanged: (val) =>
                        form['field3'] = val?.map((e) => e).toSet(),
                    initialValue: form['field3'],
                    required: true,
                  ),
                ],
              ),
            ),
          ),
        ),
        TxButtonBar.more(
          mainButton: ElevatedButton(
            onPressed: () {
              _formKey.currentState?.validate();
            },
            child: const Text('验证'),
          ),
          menus: const [
            PopupMenuItem(child: Text('选项一')),
            PopupMenuItem(child: Text('选项二')),
            PopupMenuItem(child: Text('选项三'))
          ],
        ),
      ],
    );
  }
}
2
likes
0
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

A custom component library that contains some basic UI components and provides theme configuration.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable, flutter

More

Packages that depend on tx_design