bluemix / Gradient-Widgets

Flutter widgets wrapped with gradients
Apache License 2.0
348 stars 48 forks source link

How to use this package in listview #15

Closed ABINASH56 closed 4 years ago

ABINASH56 commented 4 years ago

I tried using this package with my listview.but I am getting tons of errors .please help

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:gradient_app_bar/gradient_app_bar.dart';
import 'package:gradient_widgets/gradient_widgets.dart';

class RamList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return _myListView(context);
  }
}

Widget _myListView(BuildContext context) {
  final titles = [
    '1.1st',
    '2.2nd',
    '3.3rd',
    '4.4th',
    '5.5th',
  ];

  final numbers = [
    '1 ',
    '2 ',
    '3 ',
    '4 ',
    '5 ',
  ];

  class NamedGradient {
  NamedGradient(this.gradient, this.name);

  LinearGradient gradient;
  String name;
  }

  List<NamedGradient> gradients = [
  NamedGradient(Gradients.hotLinear, 'Hot Linear'),
  NamedGradient(Gradients.jShine, 'J Shine'),
  NamedGradient(Gradients.aliHussien, 'Golden Sunset'),
  NamedGradient(Gradients.rainbowBlue, 'Rainbow'),
  NamedGradient(Gradients.ali, 'Techno'),
  NamedGradient(Gradients.cosmicFusion, 'Cosmic Fusion'),
  NamedGradient(Gradients.backToFuture, 'Back to Future'),
  NamedGradient(Gradients.blush, 'Blush'),
  NamedGradient(Gradients.byDesign, 'By Design'),
  NamedGradient(Gradients.coldLinear, 'Cold Linear'),
  NamedGradient(Gradients.haze, 'Haze'),
  NamedGradient(Gradients.hersheys, 'Hersheys'),
  NamedGradient(Gradients.tameer, 'Tameer'),
  NamedGradient(Gradients.taitanum, 'Taitanum'),
  NamedGradient(Gradients.deepSpace, 'Deep Space'),
  ];

  functionOne() {
    Navigator.push(
        context, new MaterialPageRoute(builder: (context) => new RamOne()));
  }

  functionTwo() {
    Navigator.push(context, MaterialPageRoute(builder: (context) => RamTwo()));
  }

  functionThree() {
    Navigator.push(
        context, MaterialPageRoute(builder: (context) => RamThree()));
  }

  functionFour() {
    Navigator.push(context, MaterialPageRoute(builder: (context) => RamFour()));
  }

  functionFive() {
    Navigator.push(context, MaterialPageRoute(builder: (context) => RamFive()));
  }

  final List<Function> onTaps = [
    functionOne,
    functionTwo,
    functionThree,
    functionFour,
    functionFive
  ];

  return ListView.builder(
      itemCount: titles.length,
      itemBuilder: (context, index) {
        return Card(
            elevation: 10,
            child: InkWell(
              splashColor: Colors.green,
              highlightColor: Colors.red,
              child: Row(
                children: <Widget>[
                  Container(
                    height: 100.0,

                    // width: 42.0,
                    //color: Colors.red,
                  ),

                  Container(
                      margin: EdgeInsets.all(10),
                      child: Text(
                        numbers[index],
                      )),
                  Container(
                    height: 90.0,
                    width: 20.0,
                    color: Colors.blue,
                  ),
//Container(color: colors[index],),
                  Container(
                    margin: EdgeInsets.all(10),
                    child: Text(titles[index]),
                  )
                ],
              ),
              onTap: () => onTaps[index](),
            ));
      });
//

//  return ListView.builder(
//    itemCount: titles.length,
//    itemBuilder: (context, index) {
//      return Card(
//        color: Colors.black87,
//        //                           <-- Card widget
//        child: ListTile(
//          title: Text(
//            titles[index],
//            style: TextStyle(
//                fontSize: 18.0,
//                color: Colors.white,
//                fontWeight: FontWeight.w600,
//                fontFamily: 'Patrick Hand'),
//          ),
//          onTap: () {
//            onTaps[index]();
//          },
//        ),
//      );
//    },
//  );
}

const String _r1 = """ ##  step1

""";

class RamOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: GradientAppBar(
                gradient: LinearGradient(
                    colors: [Colors.blue, Colors.purple, Colors.red])),
            body: const Markdown(data: _r1)));
  }
}

const String _ram2 = """ 

step-2

""";

class RamTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: new Scaffold(
            appBar: GradientAppBar(
                gradient: LinearGradient(
                    colors: [Colors.blue, Colors.purple, Colors.red])),
            body: const Markdown(data: _ram2)));
  }
}

const String _ram3 = """ 

 step-3
""";

class RamThree extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: new Scaffold(
            appBar: GradientAppBar(
                gradient: LinearGradient(
                    colors: [Colors.blue, Colors.purple, Colors.red])),
            body: const Markdown(data: _ram3)));
  }
}

const String _ram4 = """ 

 step4
""";

class RamFour extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: GradientAppBar(
                gradient: LinearGradient(
                    colors: [Colors.blue, Colors.purple, Colors.red])),
            body: const Markdown(data: _ram4)));
  }
}

const String _ram5 = """ 

  step5
""";

class RamFive extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: GradientAppBar(
                gradient: LinearGradient(
                    colors: [Colors.blue, Colors.purple, Colors.red])),
            body: const Markdown(data: _ram5)));
  }
}
bluemix commented 4 years ago

please check the example that comes with the package: https://github.com/bluemix/Gradient-Widgets/tree/master/example