【FLUTTER ANDROID STUDIO and IOS】Custom Loader
Posted: 20 Mar 2021 02:07 AM PDT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String HOME_SCREEN = '/HomePage';
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class Circle extends StatelessWidget {
final double marginLeft;
final double marginRight;
final double size;
const Circle({Key key, this.marginLeft, this.marginRight, this.size})
: super(key: key);
@override
Widget build(BuildContext context) {
return new Container(
width: this.size,
height: this.size,
margin: new EdgeInsets.only(left: marginLeft, right: marginRight),
decoration: new BoxDecoration(
color: Colors.orange,
borderRadius: new BorderRadius.circular(this.size * 0.5),
boxShadow: [
new BoxShadow(
color: Colors.orangeAccent,
blurRadius: 4.0,
spreadRadius: 1.0,
offset: new Offset(1.0, 0.0),
),
new BoxShadow(
color: Colors.orange,
blurRadius: 3.0,
spreadRadius: 1.5,
offset: new Offset(1.0, 0.0),
),
],
),
);
}
}
class ScaleCircle extends AnimatedWidget {
final Animation<double> controller;
final Animation<double> animation;
final double marginLeft;
final double size;
final double marginRight;
ScaleCircle({
Key
key
,
@required this
.
controller
,
@required this
.
animation
,
@required this
.
size
,
this
.
marginLeft
=
10.0
,
this
.
marginRight
=
10.0
,
}) : super(key: key, listenable: controller);
@override
Widget build(BuildContext context) {
return ScaleTransition(scale: animation,
alignment: Alignment.center,
child: new Circle(marginRight: this.marginRight,
marginLeft: this.marginLeft,
size: this.size),
);
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import '../View/loaderview.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => new _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
}
@override
dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.red),
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new LoaderView(loaderTitle: "Loading...",
loaderWidth: 200.0,
loaderHeight: 200.0,
animationTimeMS: 3000)
],
),
),
);
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'customviews.dart';
class LoaderView extends StatefulWidget {
String loaderTitle;
double loaderWidth;
double loaderHeight;
int animationTimeMS;
double animationSpeed;
int uicount;
LoaderView({
Key
key
,
@required this
.
loaderTitle
,
this
.
loaderWidth
=
200.0
,
this
.
loaderHeight
=
200.0
,
this
.
animationTimeMS
=
5000
,
this
.
animationSpeed
=
0.15
,
this
.
uicount
=
4
});
@override
_LoaderState createState() =>
new _LoaderState(loaderWidth: this.loaderWidth,
loaderHeight: this.loaderHeight,
loaderTitle: this.loaderTitle,
animationSpeed: this.animationSpeed,
animationTimeMS: this.animationTimeMS,
uicount: this.uicount);
}
class _LoaderState extends State<LoaderView> with TickerProviderStateMixin {
String loaderTitle;
double loaderWidth;
double loaderHeight;
int animationTimeMS;
double animationSpeed;
int uicount;
_LoaderState({
Key
key
,
@required this
.
loaderTitle
,
this
.
loaderWidth
=
200.0
,
this
.
loaderHeight
=
200.0
,
this
.
animationTimeMS
=
5000
,
this
.
animationSpeed
=
0.15
,
this
.
uicount
=
4
});
List<Widget> createWidigetForAnimation() {
List<Widget> widgets = [];
// ANIMATION DRIVING FontWeight.values
final double as = this.animationSpeed;
double initialSpeed = 0.0;
// ANIMATION CLASSES
Tween<double> t = new Tween<double>(begin: 0.0, end: 1.00);
AnimationController _controller = new AnimationController(
duration: Duration(milliseconds: this.animationTimeMS),
vsync: this,
);
_controller
.repeat()
.orCancel;
for (var i = 0; i < 4; i++) {
widgets.add(new ScaleCircle(controller: _controller,
animation: t.animate(
new CurvedAnimation(
parent: _controller,
curve: new Interval(
initialSpeed,
initialSpeed + as,
curve: Curves.linear,
),
),
),
size: 25.0));
initialSpeed += as;
}
return widgets;
}
@override
void initState() {
super.initState();
}
@override
dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Container(
width: this.loaderWidth,
height: this.loaderHeight,
child: new Center(
child: new Column(
children: <Widget>[
new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: createWidigetForAnimation(),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: new Text(this.loaderTitle, style: new TextStyle(
color: Colors.orange,
fontSize: 16.0,
decoration: TextDecoration.none,
),),
),
],
),
),
);
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart';import 'Controller/SplashScreen.dart';
import 'Controller/hompage.dart';
import 'Model/Constant.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Custom Loader',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new SplashScreen(),
routes: <String, WidgetBuilder>{
HOME_SCREEN: (BuildContext context) => HomePage(),
},
);
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../Model/Constant.dart';
class SplashScreen extends StatefulWidget {
@override
SplashScreenState createState() => new SplashScreenState();
}
class SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
var _visible = true;
AnimationController animationController;
Animation<double> animation;
startTime() async {
var _duration = new Duration(seconds: 3);
return new Timer(_duration, navigationPage);
}
void navigationPage() {
Navigator.of(context).pushReplacementNamed(HOME_SCREEN);
}
@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this,
duration: new Duration(seconds: 2),
);
animation =
new CurvedAnimation(parent: animationController, curve: Curves.easeOut);
animation.addListener(() => this.setState(() {}));
animationController.forward();
setState(() {
_visible = !_visible;
});
startTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
new Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 30.0),
child: new Image.asset(
'assets/images/logo.png',
height: 25.0,
fit: BoxFit.scaleDown,
),
)
],
),
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.asset(
'assets/images/logo.png',
width: animation.value * 250,
height: animation.value * 250,
),
],
),
],
),
);
}
}
【FLUTTER ANDROID STUDIO and IOS】Image Cropper
Posted: 19 Mar 2021 07:47 PM PDT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String
IMAGE_CROPPER_SCREEN = '/ImageScreen',
ANIMATED_SPLASH = '/SplashScreen';
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:image_cropper/image_cropper.dart';
class ImageScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Image Cropper App',
debugShowCheckedModeBanner: false,
theme: new ThemeData(
accentColor: Colors.red,
primaryColor: Colors.red,
primaryColorDark: Colors.red),
home: CropScreen(
title: 'Image Cropper App',
),
);
}
}
class CropScreen extends StatefulWidget {
final String title;
CropScreen({this.title});
@override
_CropScreenState createState() => _CropScreenState();
}
enum AppState {
free,
picked,
cropped,
}
class _CropScreenState extends State<CropScreen> {
AppState state;
File imageFile;
String btnText = "Pick Image";
@override
void initState() {
super.initState();
state = AppState.free;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.title,
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Center(
child: new AspectRatio(
aspectRatio: 80 / 100,
child: imageFile != null
? Image.file(imageFile)
: Container(),
),
),
new RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(30.0)),
onPressed: () {
if (state == AppState.free) {
_pickImage();
}
else if (state == AppState.picked) {
_cropImage();
}
else if (state == AppState.cropped) {
_clearImage();
}
},
child: new Row(
children: <Widget>[
_buildButtonIcon(),
new Image.asset(
"assets/images/substract.png",
height: 24.0,
width: 24.0,
fit: BoxFit.scaleDown,
),
new Text(
btnText,
style: new TextStyle(fontSize: 20.0),
),
],
),
color: Colors.red,
textColor: Colors.white,
elevation: 5.0,
padding: EdgeInsets.only(
left: 30.0,
right: 30.0,
top: 10.0,
bottom: 10.0),
),
],
),
)
);
}
Widget _buildButtonIcon() {
if (state == AppState.free)
return Icon(Icons.add);
else if (state == AppState.picked)
return Icon(Icons.crop);
else if (state == AppState.cropped)
return Icon(Icons.clear);
else
// return Icon(Icons.check);
return Container();
}
Future<Null> _pickImage() async {
imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
if (imageFile != null) {
setState(() {
state = AppState.picked;
btnText = "Crop Image";
});
}
}
Future<Null> _cropImage() async {
File croppedFile = await ImageCropper.cropImage(
sourcePath: imageFile.path,
aspectRatioPresets: Platform.isAndroid
? [
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.original,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio16x9
]
: [
CropAspectRatioPreset.original,
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio5x3,
CropAspectRatioPreset.ratio5x4,
CropAspectRatioPreset.ratio7x5,
CropAspectRatioPreset.ratio16x9
],
androidUiSettings: AndroidUiSettings(
toolbarTitle: 'Cropper',
toolbarColor: Colors.deepOrange,
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false),
iosUiSettings: IOSUiSettings(
title: 'Cropper',
)
);
if (croppedFile != null) {
imageFile = croppedFile;
setState(() {
state = AppState.cropped;
btnText = "Clear Image";
});
}
}
void _clearImage() {
imageFile = null;
setState(() {
btnText = "Pick Image";
state = AppState.free;
});
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart';import 'Constant/Constant.dart';
import 'Screens/SplashScreen.dart';
import 'Screens/ImageCropperScreen.dart';
import 'package:flutter/material.dart';
main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new SplashScreen(),
routes: <String, WidgetBuilder>{
ANIMATED_SPLASH: (BuildContext context) => new SplashScreen(),
IMAGE_CROPPER_SCREEN: (BuildContext context) => new ImageScreen(),
},
));
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async';
import '../Constant/Constant.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SplashScreen extends StatefulWidget {
@override
SplashScreenState createState() => new SplashScreenState();
}
class SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
var _visible = true;
AnimationController animationController;
Animation<double> animation;
startTime() async {
var _duration = new Duration(seconds: 3);
return new Timer(_duration, navigationPage);
}
void navigationPage() {
Navigator.of(context).pushReplacementNamed(IMAGE_CROPPER_SCREEN);
}
@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this, duration: new Duration(seconds: 2));
animation =
new CurvedAnimation(parent: animationController, curve: Curves.easeOut);
animation.addListener(() => this.setState(() {}));
animationController.forward();
setState(() {
_visible = !_visible;
});
startTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
new Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 30.0),
child: new Image.asset(
'assets/images/logo.png',
height: 25.0,
fit: BoxFit.scaleDown,
))
],
),
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.asset(
'assets/images/logo.png',
width: animation.value * 250,
height: animation.value * 250,
),
],
),
],
),
);
}
}
【PYTHON OPENCV】QR code detection or scanner
Posted: 19 Mar 2021 06:17 PM PDT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""
QR code detection
"""
# Import required packages:
import cv2
import numpy as np
from matplotlib import pyplot as plt
def show_img_with_matplotlib(color_img, title, pos):
"""Shows an image using matplotlib capabilities"""
# Convert BGR image to RGB
img_RGB = color_img[:, :, ::-1]
ax = plt.subplot(1, 2, pos)
plt.imshow(img_RGB)
plt.title(title)
plt.axis('off')
def show_qr_detection(img, pts):
"""Draw both the lines and corners based on the array of vertices of the found QR code"""
pts = np.int32(pts).reshape(-1, 2)
for j in range(pts.shape[0]):
cv2.line(img, tuple(pts[j]), tuple(pts[(j + 1) % pts.shape[0]]), (255, 0, 0), 5)
for j in range(pts.shape[0]):
cv2.circle(img, tuple(pts[j]), 10, (255, 0, 255), -1)
# Create the dimensions of the figure and set title:
fig = plt.figure(figsize=(14, 5))
plt.suptitle("QR code detection", fontsize=14, fontweight='bold')
fig.patch.set_facecolor('silver')
# Load input image:
image = cv2.imread("qrcode_rotate_45_image.png")
# Create QR code detector:
qr_code_detector = cv2.QRCodeDetector()
# Detect and decode the QR code using qr_code_detector.detectAndDecode()
# This function returns the data, the array of vertices of the found QR code quadrangle and# the image containing the rectified binarized QR code:
data, vertices, rectified_qr_code_binarized = qr_code_detector.detectAndDecode(image)
if len(data)> 0:
print("Decoded Data: '{}'".format(data))
# Show the detection in the image:
show_qr_detection(image, vertices)
# Convert binarized image to uint8:
rectified_image = np.uint8(rectified_qr_code_binarized)
# Plot the images:
show_img_with_matplotlib(cv2.cvtColor(rectified_image, cv2.COLOR_GRAY2BGR), "rectified QR code", 1)
"""
QR code detection
"""
# Import required packages:
import cv2
import numpy as np
from matplotlib import pyplot as plt
def show_img_with_matplotlib(color_img, title, pos):
"""Shows an image using matplotlib capabilities"""
# Convert BGR image to RGB
img_RGB = color_img[:, :, ::-1]
ax = plt.subplot(1, 2, pos)
plt.imshow(img_RGB)
plt.title(title)
plt.axis('off')
def show_qr_detection(img, pts):
"""Draw both the lines and corners based on the array of vertices of the found QR code"""
pts = np.int32(pts).reshape(-1, 2)
for j in range(pts.shape[0]):
cv2.line(img, tuple(pts[j]), tuple(pts[(j + 1) % pts.shape[0]]), (255, 0, 0), 5)
for j in range(pts.shape[0]):
cv2.circle(img, tuple(pts[j]), 10, (255, 0, 255), -1)
# Create the dimensions of the figure and set title:
fig = plt.figure(figsize=(14, 5))
plt.suptitle("QR code detection", fontsize=14, fontweight='bold')
fig.patch.set_facecolor('silver')
# Load input image:
image = cv2.imread("qrcode_rotate_45_image.png")
# Create QR code detector:
qr_code_detector = cv2.QRCodeDetector()
# Detect and decode the QR code using qr_code_detector.detectAndDecode()
# This function returns the data, the array of vertices of the found QR code quadrangle and
# the image containing the rectified binarized QR code:
data, vertices, rectified_qr_code_binarized = qr_code_detector.detectAndDecode(image)
if len(data) > 0:
print("Decoded Data: '{}'".format(data))
# Show the detection in the image:
show_qr_detection(image, vertices)
# Convert binarized image to uint8:
rectified_image = np.uint8(rectified_qr_code_binarized)
# Plot the images:
show_img_with_matplotlib(cv2.cvtColor(rectified_image, cv2.COLOR_GRAY2BGR), "rectified QR code", 1)
show_img_with_matplotlib(image, "decoded data: " + data, 2)
# Show the Figure:
plt.show()
else:
print("QR Code not detected")
# Show the Figure:
plt.show()
No comments:
Post a Comment