Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:flutter/material.dart';
import 'package:animations/animations.dart';
import 'package:flutter_iroiro/second_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home 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> {
int _counter1 = 0;
int _counter2 = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
// 1.チップが押されたら画面遷移する
InputChip(
backgroundColor: Colors.black12,
avatar: CircleAvatar(
backgroundColor: Colors.grey.shade800,
child: Text('K'),
),
label: Text('A画面へ移動'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondPage()),
);
}),
// 2.チップが押されたら画面内の処理を行う
InputChip(
backgroundColor: Colors.black38,
avatar: CircleAvatar(
backgroundColor: Colors.grey.shade800,
child: Text(_counter1.toString()),
),
label: Text('Increment'),
onPressed: () {
setState(() {
_counter1++;
});
}),
// 3.チップのアイコン部分が押されたら画面内の処理を行う
Container(
margin: EdgeInsets.all(20.0),
width: 100,
padding: EdgeInsets.all(5.0),
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Colors.black12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Text(_counter2.toString())),
InkWell(
child: Icon(Icons.add),
onTap: () {
setState(() {
_counter2++;
});
})
]))
],
)),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment