flutter_toggle_tab 0.0.1 copy "flutter_toggle_tab: ^0.0.1" to clipboard
flutter_toggle_tab: ^0.0.1 copied to clipboard

outdated

Library to create Beautiful and Customized Tab/Toggle Widget on Flutter

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_toggle_tab/flutter_toggle_tab.dart';
import 'package:flutter_toggle_tab/helper.dart';

void main() {
  runApp(MyApp());
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.dark));
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Toggle Tab Sample Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _tabTextIndexSelected = 0;
  var _tabTextIconIndexSelected = 0;
  var _tabIconIndexSelected = 0;

  @override
  Widget build(BuildContext context) {
    var _listTextTabToggle = ["Tab A (10)", "Tab B (6)", "Tab C (9)"];
    var _listIconTabToggle = [
      Icons.person,
      Icons.pregnant_woman,
    ];
    var _listGenderText = ["Male", "Female"];
    var _listGenderEmpty = ["", ""];

    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter Tab Toggle"),
        elevation: 0,
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Text(
            "Basic Tab Toggle",
            style: TextStyle(fontSize: 20, fontStyle: FontStyle.italic),
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          FlutterToggleTab(
            // width in percent
            width: 90,
            borderRadius: 30,
            height: 50,
            initialLabelIndex: 0,
            selectedBackgroundColor: Colors.blue,
            selectedTextStyle: TextStyle(
                color: Colors.white, fontSize: 18, fontWeight: FontWeight.w700),
            unSelectedTextStyle: TextStyle(
                color: Colors.black87,
                fontSize: 14,
                fontWeight: FontWeight.w500),
            labels: _listTextTabToggle,
            selectedLabelIndex: (index) {
              setState(() {
                _tabTextIndexSelected = index;
              });
            },
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Text(
            "Index selected : $_tabTextIndexSelected",
            style: TextStyle(fontSize: 20),
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Divider(
            thickness: 2,
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Text(
            "With Icon",
            style: TextStyle(fontSize: 20, fontStyle: FontStyle.italic),
          ),
          Padding(
            padding: EdgeInsets.all(16),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  "Select your sex : ",
                  style: TextStyle(fontSize: 20),
                ),
                FlutterToggleTab(
                  width: 50,
                  borderRadius: 15,
                  initialLabelIndex: 0,
                  selectedTextStyle: TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                      fontWeight: FontWeight.w600),
                  unSelectedTextStyle: TextStyle(
                      color: Colors.blue,
                      fontSize: 14,
                      fontWeight: FontWeight.w400),
                  labels: _listGenderText,
                  icons: _listIconTabToggle,
                  selectedLabelIndex: (index) {
                    setState(() {
                      _tabTextIconIndexSelected = index;
                    });
                  },
                ),
              ],
            ),
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Text(
            "Selected sex : ${_listGenderText[_tabTextIconIndexSelected]} ",
            style: TextStyle(fontSize: 20),
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Divider(
            thickness: 2,
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Text(
            "With Icon Only ",
            style: TextStyle(fontSize: 20, fontStyle: FontStyle.italic),
          ),
          Padding(
            padding: EdgeInsets.all(16),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  "Select your sex : ",
                  style: TextStyle(fontSize: 20),
                ),
                FlutterToggleTab(
                  width: 40,
                  borderRadius: 15,
                  initialLabelIndex: 0,
                  selectedTextStyle: TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                      fontWeight: FontWeight.w600),
                  unSelectedTextStyle: TextStyle(
                      color: Colors.grey,
                      fontSize: 14,
                      fontWeight: FontWeight.w400),
                  labels: _listGenderEmpty,
                  icons: _listIconTabToggle,
                  selectedLabelIndex: (index) {
                    setState(() {
                      _tabIconIndexSelected = index;
                    });
                  },
                ),
              ],
            ),
          ),
          SizedBox(
            height: heightInPercent(3, context),
          ),
          Text(
            "Selected sex index: $_tabIconIndexSelected ",
            style: TextStyle(fontSize: 20),
          ),
        ],
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
111
likes
0
pub points
96%
popularity

Publisher

verified publisherlazycatlabs.com

Library to create Beautiful and Customized Tab/Toggle Widget on Flutter

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_toggle_tab