This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2017 The Chromium Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
// This app is a stateful, it tracks the user's current choice. | |
class BasicAppBarSample extends StatefulWidget { | |
@override | |
_BasicAppBarSampleState createState() => _BasicAppBarSampleState(); | |
} | |
class _BasicAppBarSampleState extends State<BasicAppBarSample> { | |
Choice _selectedChoice = choices[0]; // The app's "state". | |
void _select(Choice choice) { | |
// Causes the app to rebuild with the new _selectedChoice. | |
setState(() { | |
_selectedChoice = choice; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text('Basic AppBar'), | |
actions: <Widget>[ | |
// action button | |
IconButton( | |
icon: Icon(choices[0].icon), | |
onPressed: () { | |
_select(choices[0]); | |
}, | |
), | |
// action button | |
IconButton( | |
icon: Icon(choices[1].icon), | |
onPressed: () { | |
_select(choices[1]); | |
}, | |
), | |
// overflow menu | |
PopupMenuButton<Choice>( | |
onSelected: _select, | |
itemBuilder: (BuildContext context) { | |
return choices.skip(2).map((Choice choice) { | |
return PopupMenuItem<Choice>( | |
value: choice, | |
child: Text(choice.title), | |
); | |
}).toList(); | |
}, | |
), | |
], | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: ChoiceCard(choice: _selectedChoice), | |
), | |
), | |
); | |
} | |
} | |
class Choice { | |
const Choice({this.title, this.icon}); | |
final String title; | |
final IconData icon; | |
} | |
const List<Choice> choices = const <Choice>[ | |
const Choice(title: 'Car', icon: Icons.directions_car), | |
const Choice(title: 'Bicycle', icon: Icons.directions_bike), | |
const Choice(title: 'Boat', icon: Icons.directions_boat), | |
const Choice(title: 'Bus', icon: Icons.directions_bus), | |
const Choice(title: 'Train', icon: Icons.directions_railway), | |
const Choice(title: 'Walk', icon: Icons.directions_walk), | |
]; | |
class GradientText extends StatelessWidget { | |
GradientText( | |
this.text, { | |
@required this.gradient, | |
}); | |
final String text; | |
final Gradient gradient; | |
@override | |
Widget build(BuildContext context) { | |
return ShaderMask( | |
shaderCallback: (bounds) => gradient.createShader( | |
Rect.fromLTWH(0, 0, bounds.width, bounds.height), | |
), | |
child: Text( | |
text, | |
style: TextStyle( | |
// The color must be set to white for this to work | |
color: Colors.white, | |
fontSize: 40, | |
), | |
), | |
); | |
} | |
} | |
class ChoiceCard extends StatelessWidget { | |
const ChoiceCard({Key key, this.choice}) : super(key: key); | |
final Choice choice; | |
@override | |
Widget build(BuildContext context) { | |
final Shader linearGradient = LinearGradient( | |
colors: <Color>[Color(0xff000000), Color(0xffffffff)], | |
).createShader(Rect.fromLTWH(0.0, 0.0, 200.0, 70.0)); | |
//final TextStyle textStyle = Theme.of(context).textTheme.headline4; | |
final TextStyle textStyle = new TextStyle( | |
fontSize: 60.0, | |
fontWeight: FontWeight.bold, | |
foreground: Paint()..shader = linearGradient); | |
return Card( | |
color: Colors.white, | |
child: Container(decoration: BoxDecoration( | |
gradient: LinearGradient( | |
begin: Alignment.topRight, | |
end: Alignment.bottomLeft, | |
colors: [Colors.blue, Colors.red])), | |
child: Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
Icon(choice.icon, size: 128.0, color: Colors.black), | |
Text(choice.title, style: textStyle), | |
], | |
), | |
)), | |
); | |
} | |
} | |
void main() { | |
runApp(BasicAppBarSample()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment