pq_widgets 0.0.6 copy "pq_widgets: ^0.0.6" to clipboard
pq_widgets: ^0.0.6 copied to clipboard

一些常用的widget封装

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pq_widgets/pq_widgets.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String get poetry =>
      """竹外桃花三两枝,春江水暖鸭先知。篓篙满地芦芽短,正是河豚欲上时。两两归鸿欲破群,依依还似北归人。遥知朔漠多风雪,更待江南半月春""";

  String get richText => "竹外桃花三两枝,春江水暖鸭先知。";

  String get regex => "竹外桃<花>三两枝,春江水<暖鸭>先知。";

  @override
  void initState() {
    super.initState();
    PQText.defaultFontSize = PQFontSize.f14;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: ListView(
          children: [
            _textDemo(),
            _sizeDemo(),
            _dialogDemo(),
            _bottomActionSheetDemo(),
            CupertinoButton(
              onPressed: () {},
              child: Text("aaaa"),
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          child: Row(
            children: [
              PQTap(
                onTap: () {
                  PQText.defaultFontSize =
                      PQFontSize.f(PQText.defaultFontSize - 1);
                  setState(() {});
                },
                child: Icon(Icons.remove),
              ),
              PQTap(
                onTap: () {
                  PQText.defaultFontSize =
                      PQFontSize.f(PQText.defaultFontSize + 1);
                  setState(() {});
                },
                child: Icon(Icons.add),
              ),
            ],
          ),
          onPressed: null,
        ));
  }

  _bottomActionSheetDemo() {
    return Row(
      children: [
        TextButton(
            onPressed: () {
              PQDialog.showBottomSheetByActions(context,
                  actions: [
                    PQBottomSheetAction.normal(
                      "ssssssssssssssssss" * 100,
                      maxLines: 10,
                      fontSize: 12,
                      autoPop: false,
                    ),
                    PQBottomSheetAction.highlight("确认",
                        dividerLineColor: Colors.transparent, onTap: () async {
                      await Future.delayed(Duration(seconds: 1));
                      Future.microtask(() {
                        Navigator.of(context).push(
                          MaterialPageRoute(
                            builder: (context) => Scaffold(
                              appBar: AppBar(),
                            ),
                          ),
                        );
                      });

                    }),
                    PQBottomSheetAction.cancel(),
                  ],
                  isScrollControlled: true);
            },
            child: Text("Bottom Sheet 1")),
        TextButton(
            onPressed: () {
              PQDialog.showBottomSheet(
                  context,
                  Container(
                    color: Colors.yellowAccent,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text("aaaa"),
                      ],
                    ),
                  ),
                  isScrollControlled: false);
            },
            child: Text("Bottom Sheet 2")),
      ],
    );
  }

  _sizeDemo() {
    return Column(
      children: [
        PQSize.v(20),
        Row(
          children: [
            Icon(Icons.wrong_location),
            PQSize.h(20),
            Icon(Icons.wrong_location),
          ],
        ),
      ],
    );
  }

  _textDemo() {
    return Column(
      children: [
        PQText(poetry),
        PQText.lines(poetry),
        PQText.rich(
          richText,
          children: [
            TextSpan(text: "作者: xxx", style: TextStyle(color: Colors.orange)),
            TextSpan(
                text: "编著与2021年10月14日14:04:29",
                style: TextStyle(color: Colors.orange)),
          ],
          color: Colors.blueAccent,
        ),
        PQText.richLines(
          richText,
          children: [
            TextSpan(text: "作者: xxx", style: TextStyle(color: Colors.orange)),
            TextSpan(
                text: "编著与2021年10月14日14:04:29",
                style: TextStyle(color: Colors.orange)),
          ],
          color: Colors.blueAccent,
        ),
        PQText.regexRich(
          regex,
          RegExp(r'\<.*?\>+'),
          TextStyle(color: Colors.orange, fontSize: 22),
          color: Colors.pinkAccent,
          fontSize: 12,
        ),
      ],
    );
  }

  _dialogDemo() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        TextButton(
          child: PQText("Dialog 1"),
          onPressed: () {
            PQDialog.show(
                context: context,
                builder: (_) => NormalDialog(
                      title: "啊首付所发生的",
                      cancel: "取消",
                      submit: "确定",
                      onSubmit: () {},
                    ));
          },
        ),
        TextButton(
          child: Text("Dialog 2"),
          onPressed: () {
            PQDialog.show(
                context: context,
                builder: (_) => NormalDialog(
                      content: "啊首付所发生的",
                      cancel: "取消",
                      submit: "确定",
                      submitColor: Colors.orange,
                      onSubmit: () {},
                    ));
          },
        ),
        TextButton(
            child: Text("Dialog 3"),
            onPressed: () {
              PQDialog.show(
                  context: context,
                  builder: (_) => NormalDialog(
                        title: "阿斯蒂芬甲氨蝶呤是",
                        content: "啊首付所发生的",
                        cancel: "取消",
                        submit: "确定",
                        submitColor: Colors.orange,
                        onSubmit: () {},
                      ));
            }),
        TextButton(
          child: PQText("Dialog 4"),
          onPressed: () {
            PQDialog.showBottomSheetByActions(context, actions: [
              PQBottomSheetAction.normal("aaaa", onTap: () async {
                Future.delayed(Duration(seconds: 0))
                    .then((value) => Navigator.of(context).push(
                          MaterialPageRoute(
                            builder: (context) => Scaffold(
                              appBar: AppBar(
                                title: Text("aaa"),
                              ),
                              body: Container(),
                            ),
                          ),
                        ));
              }),
              PQBottomSheetAction.normal(
                "bbbb",
              ),
              PQBottomSheetAction.cancel(),
            ]);
          },
        )
      ],
    );
  }
}
0
likes
110
pub points
13%
popularity

Publisher

unverified uploader

一些常用的widget封装

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_screenutil

More

Packages that depend on pq_widgets