forked from firka/student-legacy
fixed some issues and added gallery save feature
This commit is contained in:
parent
5034af2fb4
commit
fa8be89aaf
@ -9,6 +9,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:screenshot/screenshot.dart';
|
import 'package:screenshot/screenshot.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||||
|
|
||||||
class PersonalityBody extends StatefulWidget {
|
class PersonalityBody extends StatefulWidget {
|
||||||
const PersonalityBody({Key? key}) : super(key: key);
|
const PersonalityBody({Key? key}) : super(key: key);
|
||||||
@ -28,6 +29,9 @@ class _PersonalityBodyState extends State<PersonalityBody> {
|
|||||||
await screenshotController.capture().then((image) async {
|
await screenshotController.capture().then((image) async {
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
final directory = await getApplicationDocumentsDirectory();
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
|
if (await File('${directory.path}/refilc_personality.png').exists()) {
|
||||||
|
await File('${directory.path}/refilc_personality.png').delete();
|
||||||
|
}
|
||||||
final imagePath =
|
final imagePath =
|
||||||
await File('${directory.path}/refilc_personality.png').create();
|
await File('${directory.path}/refilc_personality.png').create();
|
||||||
await imagePath.writeAsBytes(image);
|
await imagePath.writeAsBytes(image);
|
||||||
@ -39,6 +43,16 @@ class _PersonalityBodyState extends State<PersonalityBody> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
savePersonality() async {
|
||||||
|
await screenshotController.capture().then((image) async {
|
||||||
|
if (image != null) {
|
||||||
|
await ImageGallerySaver.saveImage(image, name: 'refilc_personality');
|
||||||
|
}
|
||||||
|
}).catchError((err) {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
user = Provider.of<UserProvider>(context);
|
user = Provider.of<UserProvider>(context);
|
||||||
@ -67,19 +81,40 @@ class _PersonalityBodyState extends State<PersonalityBody> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
Center(
|
Center(
|
||||||
child: IconButton(
|
child: Row(
|
||||||
onPressed: () async {
|
children: [
|
||||||
await sharePersonality();
|
IconButton(
|
||||||
},
|
onPressed: () async {
|
||||||
icon: const Icon(
|
await sharePersonality();
|
||||||
FeatherIcons.share2,
|
},
|
||||||
color: Colors.white,
|
icon: const Icon(
|
||||||
size: 20,
|
FeatherIcons.share,
|
||||||
),
|
color: Colors.white,
|
||||||
style: ButtonStyle(
|
size: 30,
|
||||||
backgroundColor:
|
),
|
||||||
MaterialStateProperty.all(Colors.white.withOpacity(0.5)),
|
style: ButtonStyle(
|
||||||
),
|
backgroundColor: MaterialStateProperty.all(
|
||||||
|
Colors.white.withOpacity(0.2)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await savePersonality();
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
FeatherIcons.bookmark,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 30,
|
||||||
|
),
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: MaterialStateProperty.all(
|
||||||
|
Colors.white.withOpacity(0.2)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 60),
|
const SizedBox(height: 60),
|
||||||
|
@ -42,6 +42,7 @@ dependencies:
|
|||||||
package_info_plus: ^4.0.2
|
package_info_plus: ^4.0.2
|
||||||
dotted_border: ^2.0.0+3
|
dotted_border: ^2.0.0+3
|
||||||
screenshot: ^2.1.0
|
screenshot: ^2.1.0
|
||||||
|
image_gallery_saver: ^2.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_lints: ^1.0.0
|
flutter_lints: ^1.0.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user