Skip to content

Commit

Permalink
1.添加二维码背景颜色选择器;
Browse files Browse the repository at this point in the history
  • Loading branch information
z244370114 committed Aug 29, 2023
1 parent 3081475 commit addc136
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MessageLookup extends MessageLookupByLibrary {
"lookPhoto": MessageLookupByLibrary.simpleMessage("Preview Image"),
"me": MessageLookupByLibrary.simpleMessage("My"),
"noData": MessageLookupByLibrary.simpleMessage("No history record"),
"pickAcolor": MessageLookupByLibrary.simpleMessage("Pick a color"),
"privacyPolicy": MessageLookupByLibrary.simpleMessage("Privacy Policy"),
"qrTitle": MessageLookupByLibrary.simpleMessage(
"Plain text, business card, email, mobile number, website, Wi-Fi, SMS, application"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class MessageLookup extends MessageLookupByLibrary {
"lookPhoto": MessageLookupByLibrary.simpleMessage("预览图片"),
"me": MessageLookupByLibrary.simpleMessage("我的"),
"noData": MessageLookupByLibrary.simpleMessage("暂无历史记录"),
"pickAcolor": MessageLookupByLibrary.simpleMessage("颜色选择"),
"privacyPolicy": MessageLookupByLibrary.simpleMessage("隐私政策"),
"qrTitle": MessageLookupByLibrary.simpleMessage(
"纯文本,名片,邮箱,手机号,网址,Wi-Fi,短信,应用"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"copySuccess": "Copy successful",
"clearHistory": "Are you sure you want to delete all history?",
"submits": "OK",
"pickAcolor": "Pick a color",
"noData": "No history record",
"me": "My",
"setting": "setting",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"copySuccess": "复制成功",
"clearHistory": "确定要删除所有历史记录吗?",
"submits": "确定",
"pickAcolor": "颜色选择",
"noData": "暂无历史记录",
"me": "我的",
"setting": "设置",
Expand Down
54 changes: 53 additions & 1 deletion lib/page/qr_create_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';

import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';
import 'package:ksymscan/common/constants.dart';
import 'package:qr_flutter/qr_flutter.dart';
Expand Down Expand Up @@ -28,6 +29,8 @@ class _QrCreateViewPageState extends State<QrCreateViewPage> {

var directoryPath = "";

Color selectedColor = Colors.white;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -80,7 +83,7 @@ class _QrCreateViewPageState extends State<QrCreateViewPage> {
child: QrImageView(
data: qrBarData.content!,
version: QrVersions.auto,
backgroundColor: Colors.white,
backgroundColor: selectedColor,
size: 200,
),
),
Expand Down Expand Up @@ -112,6 +115,22 @@ class _QrCreateViewPageState extends State<QrCreateViewPage> {
Icons.download_rounded,
),
),
InkWell(
onTap: () {
_openColorPicker();
},
child: Container(
width: 70,
height: 30,
decoration: BoxDecoration(
color: selectedColor,
border: Border.all(
color: Colors.grey,
width: 1.0,
),
),
),
),
IconButton.filledTonal(
onPressed: () async {
Uint8List imageunit8 =
Expand Down Expand Up @@ -182,4 +201,37 @@ class _QrCreateViewPageState extends State<QrCreateViewPage> {
),
);
}

void _openColorPicker() async {
Color color = await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(S.of(context).pickAcolor),
content: ColorPicker(
color: selectedColor,
onColorChanged: (Color color) {
setState(() {
selectedColor = color;
});
},
enableTonalPalette: false,
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(S.of(context).submits),
),
],
);
},
);
if (color != null) {
setState(() {
selectedColor = color;
});
}
}
}
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.0.0"
flex_color_picker:
dependency: "direct main"
description:
name: flex_color_picker
sha256: f37476ab3e80dcaca94e428e159944d465dd16312fda9ff41e07e86f04bfa51c
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.3.0"
flex_seed_scheme:
dependency: transitive
description:
name: flex_seed_scheme
sha256: "29c12aba221eb8a368a119685371381f8035011d18de5ba277ad11d7dfb8657f"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down

0 comments on commit addc136

Please sign in to comment.