English 中文(简体)
2. 冲破和河岸: 利用服务班和复读我的看法
原标题:Flutter & riverpod: Using service class and refresh my view

我试图用我服务的蓝色人种使用河流。

当我开始发现我的所有装置时,我想在一份清单中显示我的所有装置。 根据这一法典,我的名单上没有发生:

我的意见:

class ModulesDiscoverView extends ConsumerWidget {
  const ModulesDiscoverView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Scaffold(
      body: Column(
        children: [
          ElevatedButton(
            onPressed: () => ref.read(bluetoothServiceProvider).discoverDevices(),
            child: const Text("Discover devices"),
          ),
          Expanded(
            child: ListView.builder(
              itemCount: ref.watch(bluetoothServiceProvider).modulesScanned.length,
              itemBuilder: (context, index) {
                final module = ref.watch(bluetoothServiceProvider).modulesScanned[index];
                return Text(module.name);
              },
            ),
          ),
        ],
      ),
    );
  }
}

模块:

class Module {
  String name;  
  Module({required this.name});
} 

Bluetooth Service.dart:

final bluetoothServiceProvider = Provider(BluetoothService.new);

class BluetoothService {

  final Ref ref;
  BluetoothService(this.ref);

  StreamSubscription? subscriptionDiscoverDevices;
  List<Module> modulesScanned = [];
  FlutterReactiveBle flutterReactiveBle = FlutterReactiveBle();


  Future<void> discoverDevices() async {
    subscriptionDiscoverDevices = flutterReactiveBle.scanForDevices(withServices: [SERVICE_UUID]).listen((device) {
      modulesScanned.add(Module(name: device.name));
    }, onError: (error) {});
  }
 }
问题回答

你可以提到我如何在我的项目中使用河流。

chat_provider.dart

数据流为:ID-> Provider -> Reito-> 请求在完成要求后,数据流按顺序返回。 你们的蓝色人也可以使用存放处处理。

ChatGPT-Flutter-Web





相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签