add cam view

add 2datePicker
null_safety
小赖 4 years ago
parent 53ff216fa5
commit f2d006a84c

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:ansu_ui/ansu_ui.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@ -56,7 +58,18 @@ class _ExamplePickerState extends State<ExamplePicker> {
trailing: ASButton(
title: '时间区间选择器',
onPressed: () async {
show2DatePicker(context);
RangeDate dates = await show2DatePicker(context);
ASToast.show('${dates.start}-${dates.end}');
},
),
),
ListTile(
title: Text('图片选择器'),
subtitle: Text('ImagePicker'),
trailing: ASButton(
title: '图片选择器',
onPressed: () async {
File file = await camView(context);
},
),
),

@ -16,6 +16,8 @@ class MyApp extends StatelessWidget {
return GetMaterialApp(
title: 'Flutter Demo',
home: _ScreenAdapter(),
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,

@ -22,6 +22,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety.1"
bot_toast:
dependency: transitive
description:
name: bot_toast
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.5"
characters:
dependency: transitive
description:

@ -10,9 +10,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:image_picker/image_picker.dart';
import 'package:bot_toast/bot_toast.dart';
export 'package:flutter_screenutil/flutter_screenutil.dart';
export 'package:flutter_easyrefresh/easy_refresh.dart';
export 'package:bot_toast/bot_toast.dart';
//buttons
part 'buttons/as_button.dart';
@ -34,6 +36,8 @@ part 'bar/as_navigation_item.dart';
part 'drawer/as_drawer.dart';
part 'toast/as_toast.dart';
part 'pickers/as_date_picker.dart';
part 'pickers/as_picker_box.dart';
part 'pickers/as_city_picker.dart';
@ -60,7 +64,7 @@ part 'divider/as_divider.dart';
part 'text_field/as_search_text_field.dart';
part 'utils/screen_adapter.dart';
part 'utils/camera_util.dart';
part 'utils/camera_util.dart';part 'utils/camera_view.dart';
part 'extension/num_extension.dart';
part 'extension/list_extension.dart';

@ -165,7 +165,7 @@ class _ASButtonState extends State<ASButton> {
: BorderSide.none,
borderRadius: BorderRadius.circular(widget.radius ?? 15.5.w)),
color: widget.bgcolor ?? kForegroundColor,
splashColor: widget.splashColor??ColorTool.getSplashColor(kPrimaryColor),
splashColor: widget.splashColor,
highlightColor: widget.splashColor?.withOpacity(0.3),
elevation: 0,
focusElevation: 0,

@ -7,12 +7,12 @@ class AS2DatePicker extends StatefulWidget {
_AS2DatePickerState createState() => _AS2DatePickerState();
}
class _AS2DatePickerState extends State<AS2DatePicker>
with TickerProviderStateMixin {
class _AS2DatePickerState extends State<AS2DatePicker> {
int _selectedDay = 0;
DateTime get now => DateTime.now();
TabController _tabController;
DateTime _selectedDate;
PageController _pageController;
DateTimeRange get singleHour => DateTimeRange(
start: now,
@ -27,7 +27,14 @@ class _AS2DatePickerState extends State<AS2DatePicker>
highlightElevation: 0,
hoverElevation: 0,
color: sameDay ? kForegroundColor : kForegroundColor.withOpacity(0),
onPressed: () => setState(() => _selectedDay = index),
onPressed: () {
_pageController?.animateToPage(
index,
duration: Duration(milliseconds: 300),
curve: Curves.easeInOutCubic,
);
setState(() => _selectedDay = index);
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
height: 70.w,
child: title.text.black
@ -43,18 +50,100 @@ class _AS2DatePickerState extends State<AS2DatePicker>
color: kSecondaryColor,
borderRadius: 7.radius,
),
child: Icon(Icons.check, size: 12.w),
child: Icon(
Icons.check,
size: 12.w,
color: kLightTextColor,
),
);
Widget _renderButton(String title, VoidCallback onPressed, bool selected) {
return MaterialButton(
onPressed: onPressed,
height: 46.w,
shape: RoundedRectangleBorder(borderRadius: 23.radius),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: Row(
children: [
30.wb,
AnimatedDefaultTextStyle(
child: title.text,
style: TextStyle().size(16).copyWith(
color: selected ? kSecondaryColor : kTextColor,
),
duration: Duration(milliseconds: 300),
),
Spacer(),
AnimatedOpacity(
opacity: selected ? 1 : 0,
duration: Duration(milliseconds: 300),
child: _renderCheckBox,
),
30.wb,
],
),
);
}
Widget _buildTodayList() {
int startHour = now.hour;
int hourCount = 24 - startHour;
return ListView.builder(
padding: 8.edge,
itemBuilder: (context, index) {
bool sameItem = now.day == _selectedDate.day &&
_selectedDate.hour == startHour + index;
if (index == 0)
return _renderButton(
'一小时内',
() => setState(() => _selectedDate = now),
sameItem,
);
return _renderButton(
'${startHour + index}:00-${startHour + index + 1}:00',
() => setState(() => _selectedDate = DateTime(
now.year,
now.month,
now.day,
startHour + index,
)),
sameItem,
);
},
itemCount: hourCount,
);
}
Widget _buildOtherDayList(int offsetDay) {
return ListView.builder(
padding: 8.edge,
itemBuilder: (context, index) {
bool sameItem = (now.day + offsetDay) == _selectedDate.day &&
_selectedDate.hour == index;
return _renderButton(
'$index\:00-${index + 1}:00',
() => setState(() => _selectedDate = DateTime(
now.year,
now.month,
now.day + offsetDay,
index,
)),
sameItem,
);
},
itemCount: 24,
);
}
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
_pageController = PageController();
_selectedDate = now;
}
@override
void dispose() {
_tabController?.dispose();
_pageController?.dispose();
super.dispose();
}
@ -81,7 +170,17 @@ class _AS2DatePickerState extends State<AS2DatePicker>
),
),
),
Expanded(child: SizedBox()),
Expanded(
child: PageView(
scrollDirection: Axis.vertical,
children: [
_buildTodayList(),
_buildOtherDayList(1),
_buildOtherDayList(2),
],
controller: _pageController,
),
),
],
).expanded,
Container(
@ -91,7 +190,14 @@ class _AS2DatePickerState extends State<AS2DatePicker>
),
child: ASLongButton.solid(
title: '确认',
onPressed: () {},
onPressed: () {
Navigator.pop(
context,
RangeDate(
start: _selectedDate,
end: _selectedDate.add(Duration(hours: 1)),
));
},
),
),
],

@ -38,6 +38,7 @@ const Color kSecondaryColor = Color(0xFFE50112);
class ColorTool {
static Color getSplashColor(Color color) {
if (color == null) return Colors.transparent;
int r = color.red;
int g = color.green;
int b = color.blue;

@ -0,0 +1,7 @@
part of ansu_ui;
class ASToast {
static show(String text) {
BotToast.showText(text: text);
}
}

@ -10,3 +10,17 @@ Future<File> camFile({double maxHeight = 3000,double maxWidth = 3000}) async {
if (pickedFile == null) return null;
return File(pickedFile.path);
}
Future<File> camView(BuildContext context,
{double maxHeight = 3000, double maxWidth = 3000}) async {
File file = await camFile(maxHeight: maxHeight, maxWidth: maxWidth);
if (file == null) return null;
return await Navigator.push(context, PageRouteBuilder(
pageBuilder: (context, animation, secondAnimation) {
return FadeTransition(
opacity: animation,
child: CameraView(file: file, title: '照片选择器'),
);
},
));
}

@ -0,0 +1,63 @@
part of ansu_ui;
class CameraView extends StatefulWidget {
final File file;
final String title;
CameraView({Key key, this.file, this.title}) : super(key: key);
@override
_CameraViewState createState() => _CameraViewState();
}
class _CameraViewState extends State<CameraView> {
_buildButton({String title, Color color = kTextColor, onPressed}) {
return MaterialButton(
child: title.text.bold.size(18).copyWith(color: color),
onPressed: onPressed,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
height: 48.w,
);
}
@override
Widget build(BuildContext context) {
return ASScaffold(
title: widget.title,
body: Image.file(widget.file, fit: BoxFit.cover),
bottomNavigationBar: Material(
color: kForegroundColor,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_buildButton(
title: '重拍',
onPressed: () async {
File file = await camFile();
if (file == null) Navigator.pop(context);
Navigator.pushReplacement(context, PageRouteBuilder(
pageBuilder: (context, animation, secondAnimation) {
return FadeTransition(
opacity: animation,
child: CameraView(file: file, title: widget.title),
);
},
));
},
),
_buildButton(
title: '删除',
color: kDangerColor,
onPressed: () => Navigator.pop(context),
),
_buildButton(
title: '确认',
onPressed: () => Navigator.pop(context, widget.file),
),
].sepWidget(separate: ASDivider()),
),
),
);
}
}

@ -15,6 +15,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety.1"
bot_toast:
dependency: "direct main"
description:
name: bot_toast
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.5"
characters:
dependency: transitive
description:

@ -14,6 +14,7 @@ dependencies:
flutter_easyrefresh: ^2.1.6
lpinyin: ^1.1.0
image_picker: ^0.6.7+15
bot_toast: ^3.0.5
dev_dependencies:
flutter_test:

Loading…
Cancel
Save