This is the fourth day of my participation in the August Text Challenge.More challenges in August

Create a random color

final color = Colors.primaries[Random().nextInt(Colors.primaries.length)];
Copy the code

Scaffold adds a background color

    return Scaffold(
       //backgroundColor: Colors.green,
      backgroundColor: Color.fromRGBO(0.245.245.1.0));Copy the code

Change background transparency, do not change text transparency

  color: Colors.black.withOpacity(0.5),
Copy the code

Gets the display direction of the screen

MediaQuery.of(context).orientation == Orientation.portrait
              ? Axis.vertical
              : Axis.horizontal

Copy the code

Start page knowledge points

Notes on the Flutter Reading Project

Local picture fills the entire screen to get the phone screen size:

Size size = MediaQuery.of(context).size; Size size = MediaQuery.of(context).size;

   Size size = MediaQuery.of(context).size;
    return Scaffold(
      body: Stack(
        children: [
          Image.asset(
            'assets/images/launch_img.jpg',
            fit: BoxFit.cover,
            width: size.width,
            height: size.height,
          )
        ],
      ),
    );
Copy the code

A launch page with a countdown written with a cascade component and a location component

    return Scaffold(
      body: Stack(
        children: [
          Image.asset(
            'assets/images/launch_img.jpg',
            fit: BoxFit.cover,
            width: size.width,
            height: size.height,
          ),
          Positioned(
            child: _clipButton(),
            left: 10,
            top: MediaQuery.of(context).padding.top + 10,
          )
        ],
      ),
    );
Copy the code

A button with custom rounded corners is implemented using ClipRRect and Container

Widget _clipButton() { return ClipRRect( borderRadius: BorderRadius.circular(50), child: Container( width: 50, height: Child: 50, color: Colors. Black, the Column (mainAxisAlignment: mainAxisAlignment center, children: [Text (' skipped 'style: TextStyle(fontSize: 12, color: Colors.white)), Text('5s', style: TextStyle(fontSize: 12, color: Colors.white)) ], ), ), ); }Copy the code

A timer _timer! .cancel(); // Destroy the route

int _currentTime = 6; Timer? _timer; @override void initState() { // TODO: implement initState super.initState(); _timer = Timer.periodic(Duration(milliseconds: 1000), (Timer) { setState(() { _currentTime--; }); if (_currentTime <= 0) { _jumpRootPage(); }}); }Copy the code

The start page is a method of using routes to jump to the home page and destroy routes.

void _jumpRootPage() { _timer! .cancel(); Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (BuildContext context) => RootPage(), ), (route) => false); }Copy the code

The dart operator

Type determination operator Operator interprets as type conversion is Returns True is! Return False if the object is of the specified type 123 4 5 6 int a = 123; String b = ‘ducafecat’; String c = ‘abc’; print(a as Object); print(b is String); print(c is! String);

Conditional expression

The operator explain
condition ? expr1 : expr2 If condition is true, exPR1 is executed (and the result of execution is returned); Otherwise, exPR2 is executed and the result is returned.
expr1 ?? expr2 If expr1 is non-null, return its value; Otherwise, exPR2 is executed and the result is returned.
bool isFinish = true; String txtVal = isFinish ? 'yes' : 'no'; bool isFinish; isFinish = isFinish ?? false; or isFinish ?? = false;Copy the code

The cascade operator operator interprets.. Multiple functions can be called consecutively on the same object and member variables can be accessed.

StringBuffer sb = new StringBuffer(); sb .. write('hello') .. write('word') .. write('\n') .. writeln('doucafecat');Copy the code

The Dart in.. Cascade operation

class Person { var name; var age; Person(this.name, this.age); getInfo() { print("${this.name},${this.age}"); }} main() {var p = new Person(' Person ', 20); p.getInfo(); / /.. For cascading operations, the execution method p.. Name = "li Si".. age = 30 .. getInfo(); }Copy the code