0

I am new to flushbar widget. I build a simple code sample that results on the following compiler errors following some articles and videos on the widget. https://pub.dev/packages/flushbar

Most of the examples depend on the onPressed click event. In my case I need to do some processing before displaying of the flushbar message.

I tried with both versions: flushbar: ^1.10.0 flushbar: ^1.9.1

Could you advise what is run with the code below?

This are the compiler errors:

Running Gradle task 'assembleDebug'... Compiler message: /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flushbar-1.10.0/lib/flushbar_route.dart:303:8: Error: The method 'FlushbarRoute.install' has fewer positional arguments than those of overridden method 'OverlayRoute.install'. void install() { ^ /C:/src/flutter/packages/flutter/lib/src/widgets/routes.dart:41:8: Context: This is the overridden method ('install'). void install(OverlayEntry insertionPoint) { ^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flushbar-1.10.0/lib/flushbar_route.dart:311:18: Error: Too few positional arguments: 1 required, 0 given. super.install(); ^ Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed.

FAILURE: Build failed with an exception.

  • Where: Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780

  • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.

    Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

Here is my sample code. No errors on syntax but fails the compilation.

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

class MyHomePage extends StatefulWidget {
  MyHomePage();

  @override
  State<StatefulWidget> createState() {
    return _MyHomePage();
  }

}
class _MyHomePage extends State<MyHomePage> {
  int _selectedIndex = 2;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Flushbar')),
      body: Center(
          child:
          BottomNavigationBar(
            items: <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                icon: Icon(Icons.today),
                title: Text('Today'), // Today button.
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.business ),
                title: Text('Activities'),  // Activities.
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.save),
                title: Text('Finish'), // Finish
              ),
            ],
            currentIndex: _selectedIndex,
            selectedItemColor: Colors.amber[800],
            onTap: _onItemTapped,
          )
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      switch (index) {
        case 0:           // Today selected.
//          todayButtonPressed();
          break;
        case 1:           // Activity selected.
//          activityButtonPressed();
          break;
        case 2:           // Finish selected.
          finishButtonPressed();
          break;
      }
    });
  }

  void finishButtonPressed() async {
    // Processing record.
    // .....
    // ....
    displayFlushBar(context);
  }

  void displayFlushBar(BuildContext context) {
    Flushbar(
      title: 'Action',
      message: 'Is prohibited',
      icon: Icon(
        Icons.info_outline,
        size: 28,
        color: Colors.blue.shade300,
      ),
      leftBarIndicatorColor: Colors.blue.shade300,
      duration: Duration(seconds: 3),
    )..show(context);
  }
}
Val
  • 101
  • 1
  • 10

1 Answers1

0

This is a known issue on flushbar 1.10.0 as mentioned in this ticket. The issue has been fixed since Flutter 1.17. Upgrading the Flutter SDK should solve the issue, run flutter upgrade on your terminal to update the installed Flutter SDK.

Omatt
  • 8,564
  • 2
  • 42
  • 144