小编Flu*_*008的帖子

错误:无法将“AppStateNotifier”类型的值分配给“Widget”类型的变量

按照本教程。https://itnext.io/app-theming-in-flutter-dark-mode-light-mode-27d9adf3cee

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  runApp(
    ChangeNotifierProvider<AppStateNotifier>(
      builder: (context) => AppStateNotifier(), //<--COMPILER ERROR, details below.
      child: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return Consumer<AppStateNotifier>(
      builder: (context, appState, child) {
        return MaterialApp(
          title: 'Lockify',
          debugShowCheckedModeBanner: false,
          theme: AppTheme.lightTheme, 
          darkTheme:
              AppTheme.darkTheme, 
          home: MyHomePage(),
          themeMode: appState.isDarkModeOn ? ThemeMode.dark : ThemeMode.light,
        );
      },
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

错误:编译器消息:lib/main.dart:16:29:错误:“AppStateNotifier”类型的值无法分配给“Widget”类型的变量。

  • “AppStateNotifier”来自“package:lockify/appstatenotifier.dart”(“lib/appstatenotifier.dart”)。
  • “小部件”来自“package:flutter/src/widgets/framework.dart”(“../../Developer/flutter/packages/flutter/lib/src/widgets/framework.dart”)。构建器:(上下文)=> AppStateNotifier(),

lib/main.dart:16:16: 错误:无法将参数类型“Widget …

themes light dart flutter android-dark-theme

3
推荐指数
1
解决办法
296
查看次数

使用 Flutter API 加密读取 PEM 文件

import 'package:encrypt/encrypt.dart';
import 'package:encrypt/encrypt_io.dart';
import 'dart:io';
import 'package:pointycastle/asymmetric/api.dart';
import 'dart:async';
import 'package:flutter/services.dart' show rootBundle;

class Encrypt {
  Future<String> loadPrivateKey() async {
    return await rootBundle.loadString('assets/private_key.pem');
  }

  Future<String> loadPublicKey() async {
    return await rootBundle.loadString('assets/public_key.pem');
  }

  encryptString() async {
    print(loadPublicKey().toString());
    final publicKey =
        await parseKeyFromFile<RSAPublicKey>('${loadPublicKey()}');
    final privateKey =
        await parseKeyFromFile<RSAPrivateKey>('${loadPrivateKey()}');

    final plainText = 'James Bond';
    final encrypter =
        Encrypter(RSA(publicKey: publicKey, privateKey: privateKey));

    final encrypted = encrypter.encrypt(plainText);
    final decrypted = encrypter.decrypt(encrypted);

    print(decrypted);
    print(encrypted.base64);
  }
}
Run Code Online (Sandbox Code Playgroud)

错误:正在执行热重载...正在将文件同步到 IA 模拟器上的设备 AOSP...在 1,021 毫秒内重新加载了 707 个库中的 8 …

rsa encryption-asymmetric public-key-encryption flutter

2
推荐指数
1
解决办法
5885
查看次数