SHARE
TWEET

Untitled

a guest Sep 20th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:mobile/utils/get_text_color.dart';
  3.  
  4. class ButtonGroup extends StatelessWidget {
  5.   ButtonGroup({
  6.     Key key,
  7.     @required this.index,
  8.     @required this.length,
  9.     @required this.titles,
  10.     @required this.onPressed,
  11.     this.buttonBuilder,
  12.   }) : super(key: key);
  13.  
  14.   final int index;
  15.   final int length;
  16.   final List<String> titles;
  17.   final Function(int selectedIndex) onPressed;
  18.   final Function(BuildContext context, int i) buttonBuilder;
  19.  
  20.   final ShapeBorder leftMostShape = const RoundedRectangleBorder(
  21.     borderRadius: BorderRadius.only(
  22.       bottomRight: Radius.zero,
  23.       topRight: Radius.zero,
  24.       bottomLeft: Radius.circular(10),
  25.       topLeft: Radius.circular(10),
  26.     ),
  27.   );
  28.   final ShapeBorder centerShape = const RoundedRectangleBorder();
  29.   final ShapeBorder rightMostShape = const RoundedRectangleBorder(
  30.     borderRadius: BorderRadius.only(
  31.       bottomLeft: Radius.zero,
  32.       topLeft: Radius.zero,
  33.       bottomRight: Radius.circular(10),
  34.       topRight: Radius.circular(10),
  35.     ),
  36.   );
  37.  
  38.   @override
  39.   Widget build(BuildContext context) {
  40.     return Row(
  41.       mainAxisAlignment: MainAxisAlignment.end,
  42.       crossAxisAlignment: CrossAxisAlignment.end,
  43.       children: <Widget>[
  44.         ...Iterable<int>.generate(length).map(
  45.           (currentIndex) {
  46.             Color backgroundColor = index == currentIndex
  47.                 ? Theme.of(context).accentColor
  48.                 : Color.lerp(
  49.                     Theme.of(context).disabledColor,
  50.                     Theme.of(context).canvasColor,
  51.                     0.95,
  52.                   );
  53.  
  54.             Color textColor = getTextColor(backgroundColor);
  55.  
  56.             return RaisedButton(
  57.               color: backgroundColor,
  58.               shape: currentIndex == 0
  59.                   ? leftMostShape
  60.                   : currentIndex == length - 1 ? rightMostShape : centerShape,
  61.               child: Text(
  62.                 titles[currentIndex],
  63.                 style: Theme.of(context).textTheme.body1.copyWith(
  64.                       color: textColor,
  65.                     ),
  66.               ),
  67.               onPressed: () => onPressed(currentIndex),
  68.             );
  69.           },
  70.         ),
  71.       ],
  72.     );
  73.   }
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top