Created
August 13, 2021 03:06
-
-
Save zmtzawqlp/8abda3c688c01c0b7c8d37236e58e191 to your computer and use it in GitHub Desktop.
增大点击区域
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
import 'package:flutter/material.dart'; | |
import 'package:oktoast/oktoast.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return OKToast( | |
child: MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(), | |
), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({Key key}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
Widget text = const Text( | |
'这是测试的文字,请勿删掉', | |
maxLines: 1, | |
); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: ListView.builder( | |
itemBuilder: (BuildContext c, int index) { | |
return Container( | |
decoration: BoxDecoration(border: Border.all(color: Colors.grey)), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
Expanded( | |
child: Container( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[text, text], | |
), | |
decoration: | |
BoxDecoration(border: Border.all(color: Colors.grey)), | |
), | |
), | |
Expanded( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
getButton('A'), | |
Expanded( | |
child: Container( | |
color: Colors.lightGreen, | |
child: text, | |
), | |
), | |
getButton('B'), | |
], | |
), | |
text, | |
], | |
)), | |
Expanded( | |
child: Container( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[text, text], | |
), | |
decoration: | |
BoxDecoration(border: Border.all(color: Colors.grey)), | |
), | |
), | |
], | |
), | |
); | |
}, | |
itemExtent: 70, | |
), | |
); | |
} | |
Widget getButton(String text) { | |
return GestureDetector( | |
onTap: () { | |
showToast(text, duration: Duration(milliseconds: 500)); | |
}, | |
child: Container( | |
width: 16, | |
height: 16, | |
alignment: Alignment.center, | |
child: Text(text), | |
decoration: BoxDecoration(border: Border.all(color: Colors.red)), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment