amake / flutter_charset_detector

Flutter plugin that detects the charset (encoding) of text bytes
https://pub.dev/packages/flutter_charset_detector
19 stars 11 forks source link

Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>?' in type cast #4

Closed khjde1207 closed 1 year ago

khjde1207 commented 1 year ago

Thanks for sharing this great library.

After changing to version 2.0.0, Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>?' in type cast error started to occur.

I created a new project and tested it. Same error occurs.

The logic below only modifies the button logic from the basic flutter sample.

The test was conducted on Android.

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_charset_detector/flutter_charset_detector.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() async {
    Uint8List bytes = Uint8List.fromList("djslafjkdlsjafkldsla".codeUnits);
    DecodingResult result = await CharsetDetector.autoDecode(bytes);
    print(result.charset);
    print(result.string);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

E/flutter (18774): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>?' in type cast E/flutter (18774): #0 MethodChannel._invokeMethod platform_channel.dart:310 E/flutter (18774): E/flutter (18774): #1 CharsetDetectorAndroid.autoDecode flutter_charset_detector_android.dart:17 E/flutter (18774): E/flutter (18774): #2 _MyHomePageState._incrementCounter main.dart:66 E/flutter (18774): E/flutter (18774):

Flutter 3.13.6 • channel stable • https://github.com/flutter/flutter.git Engine • revision a794cf2681 Tools • Dart 3.1.3 • DevTools 2.25.0

amake commented 1 year ago

Sorry about that. Please see v2.0.1, which I just released now.

khjde1207 commented 1 year ago

It works fine. thank you!