Saturday, June 8, 2019

How to add slider in flutter



You can add slider in flutter with the help of “intro_slider” plugin. To integrate this please follow below steps -


Add below line in your pubspace.yam file -

dependencies:
  intro_slider: ^2.2.0


Now click on “Package get” option from top section to get this package in your app.




Now, Import below package in your file -

import 'package:intro_slider/intro_slider.dart';


Note - Make sure to add your images in pubspace.yaml file like this -

assets:
  - assets/images/photo_eraser.png
  - assets/images/photo_pencil.png
  - assets/images/photo_ruler.png



Slider images for Android and iOS


Create a new class as below -

import 'package:flutter/material.dart';
import 'package:intro_slider/dot_animation_enum.dart';
import 'package:intro_slider/intro_slider.dart';
import 'package:intro_slider/slide_object.dart';


class TutorialScreen extends StatefulWidget{

  TutorialScreen({Key key}) : super(key: key);

  @override
  TutorialScreenState createState() => new TutorialScreenState();

}


class TutorialScreenState extends State<TutorialScreen>{
  List<Slide> slides = new List();

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

    slides.add(
      new Slide(
        title: "ERASER",
        description: "Allow miles wound place the leave had. To sitting subject no improve studied limited",
        pathImage: "assets/images/photo_eraser.png",
        backgroundColor: Color(0xfff5a623),
      ),
    );
    slides.add(
      new Slide(
        title: "PENCIL",
        description: "Ye indulgence unreserved connection alteration appearance",
        pathImage: "assets/images/photo_pencil.png",
        backgroundColor: Color(0xff203152),
      ),
    );
    slides.add(
      new Slide(
        title: "RULER",
        description:
        "Much evil soon high in hope do view. Out may few northward believing attempted. Yet timed being songs marry one defer men our. Although finished blessing do of",
        pathImage: "assets/images/photo_ruler.png",
        backgroundColor: Color(0xff9932CC),
      ),
    );
  }

  void onDonePress() {
    // Do what you want
  }

  @override
  Widget build(BuildContext context) {
    return new IntroSlider(
      slides: this.slides,
      onDonePress: this.onDonePress,
    );
  }

}



Now call this from your main.dart file by using below code -

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: TutorialScreen(),
      debugShowCheckedModeBanner: false
    );
  }
}


This plugin have many options you can check all available options on below urls -



How to change project name in flutter


Solution for Android -

This is very simple in flutter, If you want to change the project name which will display on the mobile app. First, open your project in android studio or in any editor and then navigate to android/app/src/main/AndroidManifest.xml 



After this, you have to change the label value in AndroidManifest.xml  for android:label 

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label=“APP Name”
    android:icon="@mipmap/ic_launcher">


Just replace “APP Name” with your app name. Now run your project in android simulator/device. 
Note - If changes are not updating then please uninstall your existing build and install again.



Solution for iOS - To update app name in iOS you just need to navigate on below location - 

ios/Runner/Info.plist



Now search for “CFBundleName” in Info.plist file and replace its value with your app name. Please check below example - 

<key>CFBundleName</key>
<string>APP Name</string>

Now, Run the app in simulator/Device. This will update your app name.

Note - Same as Android if the app name is not updating then please uninstall your existing build and install again.


This will update the app name for both (Android and iOS).