Berkin
Berkin

Reputation: 519

Flutter Charts: Adding Library won't let me change colors in the App. What can I do?

In my flutter app i want to implement some charts so I've added the following library: import 'package:charts_flutter/flutter.dart';

But as soon as I implement it, there appears a lot of problems like for example: I can't use random colors in my Appbar and I really don't know why this happens. This is a piece of my code:

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:charts_flutter/flutter.dart';

class ZulassungenScreen extends StatefulWidget {
  @override
  _ZulassungenScreen createState() => _ZulassungenScreen();
}

@override
class _ZulassungenScreen extends State<ZulassungenScreen> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 4,
      child: Scaffold(
        appBar: AppBar(
          title: Text('This page'),
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  colors: [Color(0xffFBD23E), Color(0xffF6BE03)],
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter),
            ),
          ),
          bottom: TabBar(
            isScrollable: true,
            unselectedLabelColor: Colors.black,
            unselectedLabelStyle: TextStyle(fontWeight: FontWeight.normal),
            indicatorSize: TabBarIndicatorSize.label,```
and so on...```


It appears an error here: "colors: [Color(0xffFBD23E), Color(0xffF6BE03)],""

Can you please help me? Thank you so much!!

Upvotes: 0

Views: 96

Answers (2)

Josh
Josh

Reputation: 1151

The problem is that charts_flutter implements a custom Color class.

You can solve this by adding a prefix when importing the library:

import 'package:charts_flutter/flutter.dart' as charts;

Upvotes: 1

Berkin
Berkin

Reputation: 519

I think I got it! you simply have to add as charts; at the end of the library.

-> So like this: import 'package:charts_flutter/flutter.dart' as charts;

-> Instead of this: import 'package:charts_flutter/flutter.dart';

Upvotes: 0

Related Questions