feat(example_full, lib, android): optimisation improving, current device data
This commit is contained in:
@@ -2,9 +2,11 @@ import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nearby_service/nearby_service.dart';
|
||||
import 'package:nearby_service_example_full/domain/app_service.dart';
|
||||
import 'package:nearby_service_example_full/presentation/app.dart';
|
||||
import 'package:nearby_service_example_full/uikit/uikit.dart';
|
||||
import 'package:nearby_service_example_full/utils/files_saver.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../components/device_preview.dart';
|
||||
@@ -22,13 +24,13 @@ class _CommunicationViewState extends State<CommunicationView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<AppService>(
|
||||
builder: (context, service, _) {
|
||||
final device = service.connectedDevice;
|
||||
return Selector<AppService, NearbyDevice?>(
|
||||
selector: (context, service) => service.connectedDevice,
|
||||
builder: (context, device, _) {
|
||||
if (device == null) {
|
||||
return Center(
|
||||
child: ActionButton(
|
||||
onTap: service.stopListeningAll,
|
||||
onTap: context.read<AppService>().stopListeningAll,
|
||||
title: 'Restart',
|
||||
),
|
||||
);
|
||||
@@ -69,7 +71,9 @@ class _CommunicationViewState extends State<CommunicationView> {
|
||||
Flexible(
|
||||
child: ActionButton(
|
||||
title: 'Send',
|
||||
onTap: () => service.sendTextRequest(message),
|
||||
onTap: () => context.read<AppService>().sendTextRequest(
|
||||
message,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -100,7 +104,7 @@ class _CommunicationViewState extends State<CommunicationView> {
|
||||
Flexible(
|
||||
child: ActionButton(
|
||||
title: 'Send',
|
||||
onTap: () => service.sendFilesRequest([
|
||||
onTap: () => context.read<AppService>().sendFilesRequest([
|
||||
...files
|
||||
.map((e) => e.path)
|
||||
.where((element) => element != null)
|
||||
@@ -122,11 +126,57 @@ class _CommunicationViewState extends State<CommunicationView> {
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children: [
|
||||
...files.where((element) => element.path != null).map(
|
||||
(e) => Image.file(
|
||||
(e) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: kGreenColor),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
child: FilesSaver.isImage(e.extension)
|
||||
? Image.file(
|
||||
File(e.path!),
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Container(
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
e.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 8,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: kGreenColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (FilesSaver.isImage(e.extension)) {
|
||||
return Image.file(
|
||||
File(e.path!),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: kBlueColor),
|
||||
borderRadius: BorderRadius.circular(16)),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
e.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: kBlueColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user