feat(date):更新日期组件
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:example/exif/customer_exif_Page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_common/upload_image/look_images_widget.dart';
|
||||
import 'package:flutter_common/upload_image/upload_images_tool.dart';
|
||||
import 'package:flutter_common/flutter_common.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_editor_plus/image_editor_plus.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@@ -14,167 +9,189 @@ void main() {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp(
|
||||
title: '熊猫文旅通',
|
||||
title: 'flutter_common Demo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
appBarTheme: AppBarTheme(surfaceTintColor: Colors.transparent),
|
||||
scaffoldBackgroundColor: const Color(0xffF5F5F5),
|
||||
// useMaterial3: true,
|
||||
// colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple)
|
||||
// .copyWith(background: const Color(0xffF5F5F5)),
|
||||
scaffoldBackgroundColor: const Color(0xFFF5F7FB),
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF4D6FD5)),
|
||||
cardTheme: const CardThemeData(
|
||||
color: Colors.white,
|
||||
margin: EdgeInsets.zero,
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
home: const MyHomePage(title: '编辑图片'),
|
||||
home: const MyHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Dio 最简版:网络图片转 Uint8List
|
||||
Future<Uint8List?> networkImageToUint8ListWithDio(String imageUrl) async {
|
||||
final dio = Dio(); // 初始化 Dio 实例
|
||||
try {
|
||||
// 发起 GET 请求,响应类型设为字节数组(关键)
|
||||
final response = await dio.get<List<int>>(
|
||||
imageUrl,
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
);
|
||||
// 响应成功且数据非空时,直接转为 Uint8List
|
||||
return response.statusCode == 200 && response.data != null
|
||||
? Uint8List.fromList(response.data!)
|
||||
: null;
|
||||
} catch (e) {
|
||||
print('图片转换失败:$e'); // 捕获网络错误、URL 非法等异常
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
const MyHomePage({super.key});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final int _counter = 0;
|
||||
|
||||
Future<Uint8List?> editImage({required String url}) async {
|
||||
Uint8List? imageBytes = await networkImageToUint8ListWithDio(url);
|
||||
ImageEditor.setI18n({
|
||||
'crop': '裁剪',
|
||||
'rotate left': '左旋转',
|
||||
'rotate right': '右旋转',
|
||||
'flip': '水平翻转',
|
||||
'brush': '涂抹',
|
||||
'link': '链接',
|
||||
'save': '保存',
|
||||
'text': '文本',
|
||||
'blur': '模糊',
|
||||
'filter': '滤镜',
|
||||
'size': '大小',
|
||||
'color': '颜色',
|
||||
'background color': '背景颜色',
|
||||
'background opacity': '背景透明度',
|
||||
'reset': '重置',
|
||||
'freeform': '自由裁剪',
|
||||
'remove': '移除',
|
||||
'emoji': '表情',
|
||||
'slider color': '滑块颜色',
|
||||
'color opacity': '透明度',
|
||||
'blur radius': '模糊半径',
|
||||
});
|
||||
if (mounted) {
|
||||
Uint8List? editedImage = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ImageEditor(
|
||||
image: imageBytes,
|
||||
blurOption: null,
|
||||
filtersOption: null,
|
||||
brushOption: null,
|
||||
textOption: null,
|
||||
emojiOption: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
return editedImage;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _incrementCounter() async {}
|
||||
String _singleDateText = '未选择';
|
||||
String _rangeDateText = '未选择';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
title: const Text('flutter_common 示例首页'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildIntroCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildDemoCard(
|
||||
title: '单日选择组件',
|
||||
description: '使用 `CalendarChooseWidget` 的单选模式,适合筛选某一天的数据。',
|
||||
child: CalendarChooseWidget(
|
||||
chooseIndex: 1,
|
||||
selectedDate: DateTime.now(),
|
||||
dateTimeUtilsType: DateTimeUtilsType.yearMonthDayWord,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
tapAction: (value) {
|
||||
final startTime = value['startTime'] as DateTime?;
|
||||
setState(() {
|
||||
_singleDateText = _formatDate(startTime);
|
||||
});
|
||||
},
|
||||
),
|
||||
resultText: _singleDateText,
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
const SizedBox(height: 16),
|
||||
_buildDemoCard(
|
||||
title: '区间选择组件',
|
||||
description: '默认展示开始和结束日期,适合做报表、订单或运营时间筛选。',
|
||||
child: CalendarChooseWidget(
|
||||
selectedDate: DateTime.now(),
|
||||
dateTimeUtilsType: DateTimeUtilsType.yearMonthDay,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
tapAction: (value) {
|
||||
final startTime = value['startTime'] as DateTime?;
|
||||
final endTime = value['endTime'] as DateTime?;
|
||||
setState(() {
|
||||
_rangeDateText =
|
||||
'${_formatDate(startTime)} 至 ${_formatDate(endTime)}';
|
||||
});
|
||||
},
|
||||
),
|
||||
resultText: _rangeDateText,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: Text(
|
||||
"data",
|
||||
))
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIntroCard() {
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text(
|
||||
'项目结构速览',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
'lib/calendarcalendar 里提供了日期选择相关组件,'
|
||||
'lib/upload_image 聚合图片上传与预览能力,'
|
||||
'lib/utils 则放了日期、弹窗等通用工具。',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
height: 1.6,
|
||||
color: Color(0xFF4F5B67),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDemoCard({
|
||||
required String title,
|
||||
required String description,
|
||||
required Widget child,
|
||||
required String resultText,
|
||||
}) {
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
description,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.6,
|
||||
color: Color(0xFF5C6670),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 18),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF7F9FC),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFD9E1F2)),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text(
|
||||
'当前结果:$resultText',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF4D6FD5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime? date) {
|
||||
if (date == null) {
|
||||
return '未选择';
|
||||
}
|
||||
return DateTimeUtils.dateTimeUtilsTool(
|
||||
dateTime: date.toIso8601String(),
|
||||
dateTimeUtilsType: DateTimeUtilsType.yearMonthDay,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user