ผมลองฝึกเขียนตามคลิปครับแต่ผมเขียนแล้วติด error ไม่รู้พลาดตรงไหนช่วยหาหน่อยครับ
import 'package:flutter/material.dart';
import 'package:slide_countdown_clock/slide_countdown_clock.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: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePage createState() => _HomePage();
}
class _HomePage extends State<HomePage> {
String name = "Click";
String title = 'CountDown Clock';
Duration _duration = Duration(seconds: 10000);
GlobalKey<ScaffoldState>_key = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
/*backgroundColor: Colors.white70,
appBar: AppBar(
title: Text("Scoredy"),
centerTitle: true,
backgroundColor: Colors.amber,
),*/
body: Center(
child: SlideCountdownClock(
duration: _duration,
separator: ':',
padding: EdgeInsets.all(16.0),
textStyle: TextStyle(
fontSize: 36.0,
fontWeight: FontWeight.bold,
),
decoration: BoxDecoration(
color: Colors.white54,
shape: BoxShape.circle,
),
// ignore: deprecated_member_use
onDone: () -> _key.currentState.showSnackBar(
SnackBar(
content: Text('CountDown Finished'),),
),
),
),
);
}
}
ผมลองเขียนตามคลิปนี้ครับตอนประมาณช่วงเวลา 5.00
copy error มาวางด้วยครับ
Performing hot restart...
Syncing files to device Android SDK built for x86...
lib/main.dart:60:27: Error: Expected an identifier, but got '>'.
Try inserting an identifier before '>'.
onDone: ('') -> _key.currentState.showSnackBar(
^
lib/main.dart:60:26: Error: The operator '-' isn't defined for the class 'String'.
Try correcting the operator to an existing operator, or defining a '-' operator.
onDone: ('') -> _key.currentState.showSnackBar(
^
Restarted application in 952ms.
เคสนี้เป็นอย่างไรบ้างครับ อัพเดทกันหน่อย
ผมลองถามตนอื้นมาครับเขาบอก ชีนแท็กผิด ผมก็ไม่ค่อยเข้าใจอะครับเขาก็ไม่ได้บอกวิธีแก้ตอนนี้ยังไม่ได้เลยครับ
syntax ของ SnackBar มันจะเป็นแบบนี้ครับ
ActionChip(
elevation: 8.0,
padding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.redAccent,
child: Icon(Icons.mode_comment,color:
Colors.white,size: 20,),
),
label: Text('Message'),
onPressed: () {
_key.currentState.showSnackBar(SnackBar(
content: Text('Message...'),
));
},
backgroundColor: Colors.grey[200],
shape: StadiumBorder(
side: BorderSide(
width: 1,
color: Colors.redAccent,
)),
);
1 Like
ได้แล้วครับขอบคุณครับ แต่ของผมตรงshowSnackBar มันมีขีดถับอะครับหมายความว่าอะไรหรอครับ
มันแคบไปครับมองไม่เห็นภาพรวม ต้องแคปมาให้กว้างกว่านี้
แล้วรันแล้วใช้ได้ไหม
ใช้ได้ครับแต่ผมไม่เข้าใจว่าทำไมถึงมีขีดทับอะครับ
ข้อถามข้อสุดท้ายครับ😅 ทำนาฬิกาลักษณะแบบนี้สามารถทำเหมือนใส่เลขตามที่ต้องการแล้วนับถ่อยหลังได้ไหมครับเหมือนEditText ที่ในเวลาตามที่ต้องการแล้วกดปุ่มจะเริ่มนับได้อะครับ แล้วทำยังไงหรอครับ หรือมีตัวอย่างที่พอศึกษาได้ไหมครับ